标签:
公司App里面有个需求,即所有界面都是竖屏,且不允许横屏切换,唯独有一个播放视频的界面允许横屏,大家都知道视频播放适配最大的播放屏幕那样是最好的。从网上多方查找资料,查到了这么一篇文章:
最终,根据此需求处理如下: 首先,确保App本身应该允许转屏切换:
我的App里面UITabBarController是根视图控制器,所以首先创建一个UITabBarController的子类,并设定允许转屏:
(这些要放在根视图控制器里面, 如果你的应用根视图是UINavigationController, 就放在那里面就好)
#pragma mark 转屏方法重写
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return [self.viewControllers.firstObject supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate{
return self.viewControllers.firstObject.shouldAutorotate;
}
//self.topViewController是当前导航显示的UIViewController,这样就可以控制每个UIViewController所支持的方向啦!
-(BOOL)shouldAutorotate{
return [self.topViewController shouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
}
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
// 是否支持屏幕旋转
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeRight;
}
注意:跳转到播放器要使用模态进来, 用Push会报错
[self presentViewController:playerVC animated:YES completion:nil];
标签:
原文地址:http://blog.csdn.net/qq_22157341/article/details/51365249