【问题标题】:iPhone Interface orientation is incorrectiPhone 界面方向不正确
【发布时间】:2014-07-15 04:56:19
【问题描述】:

在 iPhone 上 - 我的第一个 ViewController 支持所有界面方向。不过,最初的行为是,当我启动应用程序时,主 ViewController 应该始终是纵向的。

为了克服应用启动时手机处于横向的情况,我创建了一个只支持纵向的虚拟ViewController,从它启动应用并立即推送主ViewController。确实,主要的ViewController 是纵向的,但是在执行时:

self.interfaceOrientation

结果是横向(类似于手机的方向)。
我希望它会返回肖像,这会导致问题。
在这种情况下,如何获取ViewController 而不是设备的真实方向?

【问题讨论】:

  • 你试过preferredInterfaceOrientationForPresentation吗?
  • 是的,不幸的是没有帮助,因此求助于虚拟视图控制器的破解

标签: ios iphone objective-c uiviewcontroller uideviceorientation


【解决方案1】:

您需要覆盖您的 UINavController 以在需要时设置纵向方向。就是 Vihba 的意思。

问题是 navController 保持最后一个视图的方向...

【讨论】:

    【解决方案2】:

    **使用此代码*****

    您也可以参考以下链接: How to force a UIViewController to Portrait orientation in iOS 6

    @implementation UINavigationController (Rotation_IOS6)
    
    -(BOOL)shouldAutorotate
    
    {
    
    return [[self.viewControllers lastObject] shouldAutorotate];
    
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    
    {
    
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
    
    }
    
    -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    
    {
    
        return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多