乐视视频转屏问题

现象:
4.0.5版本上,乐视的转屏没有问题,但4.2版本上,乐视转屏会导致整个屏幕布局混乱

原因:
我们代码的底层为 UITabBarController写了一个超类 UITabBarController+HDFUITabBarController.m

- (BOOL)shouldAutorotate {
   
return NO;
}
-(
UIInterfaceOrientationMask)supportedInterfaceOrientations {
   
return UIInterfaceOrientationMaskPortrait;
}
-(
UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
   
return UIInterfaceOrientationPortrait;
}
这几句代码的效果是把整个app中所有的页面的转屏开关给关闭了,而乐视4.2demo正确转屏的执行前提是需要打开这些按钮的,所以,直接替换乐视4.2的转屏demo会出现导航栏布局全部混乱的问题

解决办法:
1、找到appDelegate中方法:
-( UIInterfaceOrientationMask )application:( UIApplication *)application supportedInterfaceOrientationsForWindow:( UIWindow *)window
这个类会在每次手机转屏前触发,这个类返回的是一个mask码
返回哪个方向就表示app当前支持哪个方向的转屏,


2、设置一个常驻内存单例类: HDFInterfaceOrientationsManager,控制那些页面可以转屏,哪些页面不可以转屏, init方法 默认不可转屏,
+ (instancetype) sharedManager {
   
static dispatch_once_t once;
   
static id instance;
   
dispatch_once(&once, ^{
        instance = [
self new];
    });
   
return instance;
}

- (
instancetype)init {
   
if ((self = [super init])) {
       
_supportAllOrientations = NO;
    }
   
return self;
}



3、appDelegate中设置如下,如果当前页面转屏开关没有打开,则默认返回 UIInterfaceOrientationMaskPortrait,不支持转屏;如果当前页面转屏开关有打开,则检测当前
-( UIInterfaceOrientationMask )application:( UIApplication *)application supportedInterfaceOrientationsForWindow:( UIWindow *)window
{

if ([[ HDFInterfaceOrientationsManager sharedManager ] supportAllOrientations ]) {
                                            //这里是控制转屏状态下的弹窗展示方向,要和当前屏幕方向一致
                    if (window. windowLevel == UIWindowLevelAlert ) {
                        if ([application statusBarOrientation ]== UIInterfaceOrientationPortrait ) {
                                return UIInterfaceOrientationMaskPortrait ;
}
if ([application statusBarOrientation ]== UIInterfaceOrientationLandscapeLeft ) {
return UIInterfaceOrientationMaskLandscapeLeft ;
}
if ([application statusBarOrientation ]== UIInterfaceOrientationLandscapeRight ) {
return UIInterfaceOrientationMaskLandscapeRight ;
}
}
return UIInterfaceOrientationMaskAllButUpsideDown ;
}
else {
return UIInterfaceOrientationMaskPortrait ;
}

}

4、在需要支持转屏的页面
  • 页面即将展示时 [HDFInterfaceOrientationsManager sharedManager].supportAllOrientations = YES;
  • 页面即将消失时 [HDFInterfaceOrientationsManager sharedManager].supportAllOrientations = NO;


苹果文档上:  
UITabBarController is rotatable if all of its view controllers are rotatable.
UITabBarController在他挂的控制器都可旋转的情况下,也是可旋转的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值