locking方向不适用于ipad ios 8 swift xcode 6.2

我像这样将通用应用程序设置的应用程序方向locking为肖像

肖像

但仍然当我在iPad上运行我的应用程序,它旋转!?

那么我应该在哪里locking方向?

为什么苹果将这个function添加到设置,而它不工作!

更新:

我试图实现这个viewController作为一般的所有viewController以及。

import Foundation import UIKit class GeneralViewController: UIViewController { override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) let value = UIInterfaceOrientation.Portrait.rawValue UIDevice.currentDevice().setValue(value, forKey: "orientation") } override func supportedInterfaceOrientations() -> Int { return Int(UIInterfaceOrientationMask.Portrait.rawValue) } override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation { return UIInterfaceOrientation.Portrait } override func shouldAutorotate() -> Bool { return false } } 

这张照片取自我的应用程序的主navigationController。

答案图1

仍然没有工作!

这件事到底是怎么运作的?

您不需要额外的代码,我正在使用Xcode 7.0.1,我注意到当我locking屏幕方向为只有肖像,它只locking在iPhone中,也locking在iPad中,您需要从设备中selectiPad (而不是通用),并检查肖像,并取消其他人,然后再次返回设备为通用,因为我发现通用只反映在iPhone中,这可能是在Xcode的某种错误。

你可以覆盖你的视图控制器方法shouldAutorotate

 override func shouldAutorotate() -> Bool { return false } 

如果您的视图控制器embedded在导航控制器中,您可以创build一个自定义导航控制器,如下所示:

 class PortraitNavigationController: UINavigationController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } override func shouldAutorotate() -> Bool { return false } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ } 

我也有同样的问题。 我的工作是 – >在设备types中selectiPad而不是通用 – >取消选中除肖像之外的其他三个选项 – >再次select通用。 完成。

这将是一个评论添加到穆罕默德Elrashidy解决scheme,但我没有评论的声誉。 我正在使用XCode 9.1和Swift 3。

我的应用程序需要一些graphics屏幕自动旋转,但所有其他屏幕保持固定。 我的问题是“常规”>“部署信息”中的“iPad”设备configuration与iPhone和通用设备configuration不一致。 我为iPhone和Universal检查了“肖像”,“风景左转”和“风景右转”,但检查了iPad的所有方向(包括“颠倒”)。 简单地取消“颠倒”导致iPad设备在我的Swift逻辑中遵守shouldAutorotate和supportedInterfaceOrientations调用。

我的Info.plist现在看起来像下面这样,我可以以编程方式打开或closuresiPad的自动旋转。

 <key>UISupportedInterfaceOrientations</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array> <key>UISupportedInterfaceOrientations~ipad</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array>