[经验]iOS app整体是竖屏(横屏),某个页面却支持横竖屏

一个app 整体上是横屏,即info.plist中设置如下图。但是在某个页面需要支持横屏。通常在进入那个页面的时候会crash。

2016-08-30 17:38:30.224 Video[991:372909] *** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [VideoPlayerViewController shouldAutorotate] is returning YES'。

[经验]iOS app整体是竖屏(横屏),某个页面却支持横竖屏_第1张图片

但是,又想对某个页面支持横竖屏。需要在AppDelegate中做如下设置。这里VideoPlayerViewController是需要横屏的页面

 

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    VideoPlayerViewController* videoPlayerVC = [VideoPlayerViewController defaultVideoPlayerViewController];
    if (VideoPlayerViewController展示时候){
        return UIInterfaceOrientationMaskLandscape;
    }
    return UIInterfaceOrientationMaskPortrait;
}

[注意]:横屏的VC,它所在NavigationContrller的shouldAutorotate和supportedInterfaceOrientations也需要针对,这个VC进行单独处理。也就是:从window到这个controller的一路,都要兼容:window—>navigatioonController—>UITabbarController—>横屏VC

 

你可能感兴趣的:(iOS,UI层)