【问题标题】:iOS how to stop view rotateiOS如何停止视图旋转
【发布时间】:2011-03-14 08:43:56
【问题描述】:

我希望我的 iPad 应用程序在您旋转 iPad 时停止旋转。我想停止旋转每个视图。

有什么帮助吗?

【问题讨论】:

    标签: iphone ios ipad


    【解决方案1】:

    如果您想停止整个应用程序的旋转,那么只需在应用程序 info.plist 文件中更改 支持的界面方向初始界面方向属性为纵向或横向取决于您

    【讨论】:

    • 这非常简单实用。有没有办法在一个视图控制器中覆盖它?我有 10 个视图控制器,其中一个需要横向,但其余的我使用此方法限制为仅纵向。
    • 如果是这种情况,您必须重写方法 - (NSUInteger)supportedInterfaceOrientations { return __orientation; } 在每个视图控制器中
    【解决方案2】:

    在 iOS6 中,shouldAutorotateToInterfaceOrientation 已被弃用。请同时覆盖 supportedInterfaceOrientationspreferredInterfaceOrientationForPresentation

    Please see

    【讨论】:

    【解决方案3】:

    只需检查视图控制器的自动调整大小属性即可。

    (修正语法错误)

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        if(interfaceOrientation == UIInterfaceOrientationPortrait)
            return YES;
    
        return NO;
    }
    

    【讨论】:

      【解决方案4】:

      在我的项目的info.plist中,我删除了iPad上的一些键Supported interface orientations,如下图(我只支持纵向)

      【讨论】:

        【解决方案5】:

        全局可控旋转锁的主要思想是为每个视图控制器编写包含锁机制的UIViewController类。

        你只需要全局修改supportedInterfaceOrientations方法

        - (NSUInteger)supportedInterfaceOrientations
        {
            return __orientation;
        }
        

        这里__orientation是静态变量,可以通过category方法设置。

        类的完整实现呈现here

        【讨论】:

          【解决方案6】:

          请像这样更新您的 projectname.plist。支持的界面方向只有一个对象“纵向(底部主页按钮)”

          【讨论】:

            【解决方案7】:

            我强烈建议不要在 iPad 上停止旋转,因为在 iPad 上支持旋转是必须的。这是因为 iPad 没有像 iPhone 那样的正常握持方式,iPhone 通常以纵向视图(AKA Vertical)握持。所以你必须把选择权留给用户来最终锁定方向

            HIG 实际上并没有将此作为要求,而是作为建议,但有很多应用被此问题拒绝。

            顺便说一句,如果你想这样做是为了限制视图控制器的数量,你应该实现:

            - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
            
                if(interfaceOrientation == UIInterfaceOrientationPortrait){
                    return YES;
                }
            }
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2014-05-23
              • 2012-05-31
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多