如何确保唯一允许的方向是纵向或倒置纵向?
我在项目设置中进行了更改,但在我的 GameViewController 中进行更改时遇到了问题。
我需要修改这个函数:
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return .AllButUpsideDown
} else {
return .All
}
}
但是,“UIInterfaceOrientationMask”结构没有只允许纵向和倒置纵向的选项。
最佳答案
您必须在项目设置中允许所有方向,然后除了 GameViewController
之外,您的 viewController 中唯一允许的方向是纵向或颠倒纵向:
// 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
}
}
关于ios - 屏幕方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30836724/