屏幕方向? [英] Orientation of screen?

查看:67
本文介绍了屏幕方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确保仅允许纵向为纵向"或上下颠倒"?

How do I make sure that the only orientations allowed are Portrait or Upside down portrait?

我在项目设置中进行了更改,但是在我的GameViewController中进行更改时遇到了麻烦.

I made the change in the project settings, but I'm having trouble making the change in my GameViewController.

我需要在此功能中进行更改:

I need to make the change in this function:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return .AllButUpsideDown
    } else {
        return .All
    }
}

但是,"UIInterfaceOrientationMask"结构没有仅允许纵向和上下颠倒肖像的选项.

However, the "UIInterfaceOrientationMask" structure doesn't have an option that only allows portrait and upside down portrait.

推荐答案

您必须在项目设置中允许所有方向,然后除 GameViewController 之外,viewController中仅允许纵向为纵向或上下颠倒的纵向>:

You have to allow all orientations in the project settings, then only orientations allowed are Portrait or Upside down portrait in your viewController except the GameViewController:

// BaseViewController
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return UIInterfaceOrientationMask.Portrait.rawValue | UIInterfaceOrientationMask.PortraitUpsideDown.rawValue
    } else {
        return .All
    }
}

最后在 GameViewController 中:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return .AllButUpsideDown
    } else {
        return .All
    }
}

这篇关于屏幕方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆