Cle*_*sou 20 iphone xcode orientation ios8
我有一个在iOS8(XCode 6.1.1)中开发的通用应用程序.它将支持所有4个方向(左,右,纵向和上下颠倒).
问题在于,尽管在XCode中检查了支持方向的四个选项,但只有左,右和纵向正常工作.那么,XCode或iOS8上是否存在错误?我info.plist显示了所有支持的方向,但是当我在模拟器或设备上运行应用程序时,它不会在翻转时"翻转"方向.(PS:它是单视图应用程序,它没有任何导航控制器).
谢谢!
Cleverson
Cle*_*sou 15
好吧,我已经找到了项目配置选项的目的...在选项中您说"我的应用程序支持这些方向"而不是"我的应用程序必须使用这四个选项"...所以,在iPhone上你必须明确说明一个特定的ViewController支持所有方向(倒置不会成为默认方向的一部分,原因我不知道)...代码应该像这样支持所有方向:
override func supportedInterfaceOrientations() -> Int{
return Int(UIInterfaceOrientationMask.All.rawValue)
}
Run Code Online (Sandbox Code Playgroud)
Ara*_*kan 13
使用Swift 2.1,您可以简化@ Cleversou的答案:
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask
{
return .All
}
Run Code Online (Sandbox Code Playgroud)
使用Swift 2.3
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
return .all
}
Run Code Online (Sandbox Code Playgroud)
小智 13
如果您在导航控制器或标签栏控制器内运行,则需要在子类中执行相同的重写或使用扩展名覆盖所有实例:
extension UINavigationController {
override public func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .All
}
}
extension UITabBarController {
override public func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .All
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:从Swift 3.0/iOS 9开始(可能更早),这将是:
extension UINavigationController {
override open var supportedInterfaceOrientations : UIInterfaceOrientationMask {
return .all
}
}
extension UITabBarController {
override open var supportedInterfaceOrientations : UIInterfaceOrientationMask {
return .all
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7279 次 |
| 最近记录: |