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

本文解决了一个iOS应用在特定页面支持横竖屏切换时遇到的问题。当应用整体设置为横屏时,试图在某个页面切换到竖屏会导致程序崩溃。通过在AppDelegate中根据不同页面需求动态调整支持的方向解决了该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一个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'。

但是,又想对某个页面支持横竖屏。需要在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

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值