【问题标题】:How to rotate screen to landscape?如何将屏幕旋转为横向?
【发布时间】:2011-01-17 19:38:16
【问题描述】:

如何将屏幕旋转为横向?

你能推荐简单的代码吗?

【问题讨论】:

标签: iphone


【解决方案1】:
【解决方案2】:

这比你最初想象的要复杂!经过多次讨论,这篇博文(后面有进一步讨论的链接)包含最清晰的答案:

How to Switch to Landscape Mode at will

【讨论】:

    【解决方案3】:

    在 uiViewController 你应该有方法

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

    为了自动旋转。

    如果您的应用程序有一个 uiTabBarController,那么您必须继承 UITabBarController 并将方法也添加到它。像这样的东西:

    @interface MyTabBarController : UITabBarController {
    
    }
    
    @end
    
    #import "MyTabBarController.h"
    
    @implementation MyTabBarController
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return YES;
    }
    
    @end
    

    【讨论】:

    • – shouldAutorotateToInterfaceOrientation:在 iOS 6.0 中已弃用。见this
    【解决方案4】:

    感谢索琳娜。需要 UITabBarController shouldAutorotateToInterfaceOrientation: 给了我各种各样的挫败感,因为它不是我出于任何原因子类化的类(即,默认功能对我的应用程序来说很好)。

    作为一种比子类化更轻量级的解决方案,我使用了一个类别(可能都一样,但看起来更轻量级)。

    @interface UITabBarController (WithRotation)
    @end
    
    @implementation UITabBarController (WithRotation)
    - (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {
        return YES;
    }
    @end
    

    附言如果您只想支持某些方向,请测试 interfaceOrientation 并仅在适当的方向上返回 YES。

    p.p.s. info.plist Supported interface orientations 是干什么用的?似乎唯一重要的是从shouldAutorotateToInterfaceOrientation:返回的内容

    【讨论】:

    • – shouldAutorotateToInterfaceOrientation:在 iOS 6.0 中已弃用。见here
    【解决方案5】:

    只需在您的视图控制器文件中实现它, 你就完成了。

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

    【讨论】:

    • – shouldAutorotateToInterfaceOrientation:在 iOS 6.0 中已弃用。见this
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多