【问题标题】:Allow Landscape and Portrait but force app to remain in Portrait - iOS允许横向和纵向但强制应用保持纵向 - iOS
【发布时间】:2013-01-08 23:46:46
【问题描述】:

我有一个设计为纵向运行的应用程序,一切都很好。但是我已经实现了 Mobfox 的 vAd,需要横向模式。

目前调用vAD时出现以下错误

2013-01-08 23:44:05.109 Tv - IOS[1422:907] mobfox video did load
2013-01-08 23:44:05.125 Tv - IOS[1422:907] *** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

所以我认为修复将允许应用程序中的横向。

我需要强制应用以纵向运行,但在调用 vAd 时允许横向运行

所以回顾一下:

我需要在正常应用视图期间仅纵向方向,而在 mobFox vAd 视图期间横向/纵向可见。

【问题讨论】:

    标签: ios xcode device-orientation mobfox


    【解决方案1】:

    为shouldAutorotate返回NO:

    -(BOOL)shouldAutorotate {
      return NO;
    }
    

    或者如果是YES你需要返回supportedInterfaceOrientations(至少一个),这里只允许纵向:

    - (NSUInteger)supportedInterfaceOrientations{
      return UIInterfaceOrientationMaskPortrait;
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
          return UIInterfaceOrientationMaskAll;
      }
    }
    

    【讨论】:

    • 实际上代码在返回“NO”时不允许旋转。试试看。否则返回 'YES' 和 'UIInterfaceOrientationMaskAllButUpsideDown'
    • 提供的代码被 mobfox 的 vAd 覆盖,我收到以下错误代码“支持的方向与应用程序没有共同的方向,并且 shouldAutorotate 返回 YES”
    • 错误消息说您正在从 shouldAutorotate 返回 YES。因此,您没有像上面那样更改代码。这些方法不应该在您的根控制器中!
    • 这些方法在 rootView 控制器中,我已经将您的建议放在了 deffo 中。这是一个奇怪的。这就是为什么我认为 Mobfox vAd 正在覆盖 rootview 控制器中的 ShouldAutorotate 方法
    • 然后尝试将其设置为“YES”并返回“UIInterfaceOrientationMaskAllButUpsideDown”
    【解决方案2】:

    好的,睡了这个之后我终于解决了这个问题。

    解决方案:我必须继承 UINavigationController 并覆盖自动旋转方法并允许在项目>目标>摘要设置中进行所有旋转

    - (BOOL)shouldAutorotate {
    return NO;
    }
    
    - (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
    }
    // pre-iOS 6 support 
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
    }
    

    【讨论】:

    • 你剥夺了我的答案,然后添加一个相同的答案并给它你的投票!请解释一下。
    • 我没有意识到我这样做了我很抱歉,我已将其恢复为原始状态。请接受我的道歉。
    猜你喜欢
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    相关资源
    最近更新 更多