问题一:屏幕旋转
将 player.superView (展示给用户的showView)设置新的 transform
self.showView.transform = CGAffineTransformMakeRotation(-M_PI_2); //屏幕左转
//CGAffineTransformMakeRotation(M_PI_2) 屏幕右转
//CGAffineTransformMakeRotation(M_PI) 屏幕翻转
//CGAffineTransformIdentity 屏幕恢复竖直
如果开启自动横竖屏监测,在开启播放的时候注册
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
停止播放的时候移除通知
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
注意,在屏幕旋转方法里做好 全屏按钮和横屏旋转监测通知的冲突。
//无效操作 (不可全屏 改变方向和当前方向一致 手机反向)
if (!_canFullScreen ||_currentOrientation == orientation ||orientation == UIInterfaceOrientationPortraitUpsideDown) { return; }
问题二:状态栏横屏
步骤一 配置plist文件:
在plist文件中将 View controller-based status bar appearance 设置为NO
步骤二 重写根控制器代码:
标签控制器
- (BOOL)shouldAutorotate {
return self.selectedViewController.shouldAutorotate;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return self.selectedViewController.supportedInterfaceOrientations;
}
导航控制器
-(BOOL)shouldAutorotate {
return self.topViewController.shouldAutorotate;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return self.topViewController.supportedInterfaceOrientations;
}
播放器所在控制器
-(BOOL)shouldAutorotate { return NO; }
问题三:横屏键盘
步骤一:
在AppDelegate.h中 写一个属性
@property (nonatomic, assign)BOOL allowRotation;
步骤二:
在AppDelegate.m 中 重写方法
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)nowWindow {
if (_allowRotation) { return UIInterfaceOrientationMaskLandscape; } else {
return UIInterfaceOrientationMaskPortrait; }
}
步骤三:
播放器横屏时候:
#define GetAPPDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)
GetAPPDelegate.allowRotation = YES;
播放器竖屏时候:
GetAPPDelegate.allowRotation = NO;
注意:横屏键盘用于弹幕输出,如果页面竖屏键盘和横屏键盘同时存在的时候,要做好 键盘呼出收起 的通知冲突。