首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在iOS 8中启动应用程序时,如果设备处于横向,如何强制纵向

在iOS 8中启动应用程序时,如果设备处于横向,如何强制纵向
EN

Stack Overflow用户
提问于 2015-01-26 06:52:11
回答 2查看 1.3K关注 0票数 0

我的应用程序允许所有四种方向,但是rootviewcontroller应该只允许纵向方向。

我覆盖了rootviewcontroller中的supportedInterfaceOrientations方法,但是如果在应用程序启动时设备处于横向,那么视图控制器将无法正确显示横向,即使只允许纵向。这是iOS 8特有的问题。

代码语言:javascript
复制
override func supportedInterfaceOrientations() -> Int {
    return UIInterfaceOrientation.Portrait.rawValue
}
EN

回答 2

Stack Overflow用户

发布于 2015-01-26 07:38:52

在ViewController中:

代码语言:javascript
复制
- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

Swift版本:

代码语言:javascript
复制
override func shouldAutorotate() -> Bool {
    return true
}
override func supportedInterfaceOrientations() -> Int {
    return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}
票数 1
EN

Stack Overflow用户

发布于 2015-01-27 00:28:51

对于我实现AppDelegate函数应用程序来说,supportedInterfaceOrientationsForWindow做到了

代码语言:javascript
复制
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow) -> Int {

    if let viewController = self.window?.rootViewController?.presentedViewController as? PortraitViewController{

        return Int(UIInterfaceOrientationMask.Portrait.rawValue)
    }else{

        return Int(UIInterfaceOrientationMask.All.rawValue)
    }

}

其中PortraitViewController应替换为您的根视图控制器类的名称

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28142530

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档