【问题标题】:How to restrict rotation to only one view controller?如何将旋转限制为仅一个视图控制器?
【发布时间】:2011-10-28 03:29:38
【问题描述】:

有没有办法将视图旋转限制在一个视图控制器上? 例如,应用程序的其余部分保持纵向模式,但一个视图可以处于横向或纵向模式。

【问题讨论】:

    标签: ios iphone screen-rotation


    【解决方案1】:

    使用这个委托方法来控制旋转,

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        {
            // Return YES for supported orientations
            return YES;
        }
        else
        {
            return NO;
        }
    }
    

    对于您要支持的方向返回 YES,对于其他方向返回 NO。您可以在所有视图控制器中实现这一点。

    【讨论】:

      【解决方案2】:

      您可以实现每个UIViewControllershouldAutorotateToInterfaceOrientation: 方法。为您希望给定视图控制器支持的方向返回 YES 将产生所需的结果。

      the UIViewController docs

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-13
        • 1970-01-01
        相关资源
        最近更新 更多