代码之家  ›  专栏  ›  技术社区  ›  jMelnik

适用于iOS 6的多个UIInterfaceOrientations应用程序

  •  3
  • jMelnik  · 技术社区  · 12 年前

    我在尝试从iOS 6设置新的UIInterfaceOrientations时遇到了困难。

    正在恢复我的应用程序:

    • 我的应用程序有很多视图;
    • 几乎每个视图都应该以纵向显示;
    • 我的2个视图(与一起播放视频的视图 MPMoviePlayerViewController )应向左、向右和纵向旋转。

    我最初的想法是将应用程序支持的方向设置为Portrait,然后从视频播放器视图更改(不知道如何更改)支持的方向。

    处理这个问题的最佳方法是什么?

    提前谢谢!

    2 回复  |  直到 12 年前
        1
  •  2
  •   Community user43968    7 年前

    通过将支持的界面方向设置为我所需要的所有方向(纵向、横向、右侧和左侧)并添加一个,解决了这个问题 Category 属于 UINavigationController

    我将类别添加到 UI导航控制器 我想保持肖像模式,并像对待iOS 6旋转一样 this post 以下为:

    @implementation UINavigationController (Rotation_IOS6)
    
    -(BOOL)shouldAutorotate
    {
        return NO;
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationPortrait;
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationPortrait;
    }
    
    @end
    

    实现后,我仍然有一些问题,因为代码是这样的:

    [self.window.rootViewController presentModalViewController:controller animated:NO]; 
    

    而不是这样:

    [self.navigationController pushViewController:controller animated:NO];
    

    通过上述更改,我能够将整个应用程序保持在人像模式,并让视频播放器视图保持旋转,因为它们的方法(shouldRotate和supportedInterfaceOrientations)没有被覆盖。

        2
  •  1
  •   Community user43968    7 年前

    查看我的帖子: https://stackoverflow.com/a/12538622/1575017 这是一样的,但对你来说是颠倒的方向。