如何在横向模式下呈现ViewController

时间:2015-06-04 12:18:50

标签: ios iphone swift

我想以横向模式呈现UIView控制器,并禁用此UIViewController的任何其他旋转。我尝试了以下操作,但用户仍然可以旋转出风景。

override func viewDidLoad() {
    super.viewDidLoad()
    applyLandscapeAndLock()
    build()
    // Do any additional setup after loading the view.
}

override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
    return UIInterfaceOrientation.LandscapeLeft
}

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

override func supportedInterfaceOrientations() -> Int {
    return UIInterfaceOrientation.LandscapeLeft.rawValue
}

func applyLandscapeAndLock() {
    let value = UIInterfaceOrientation.LandscapeLeft.rawValue
    UIDevice.currentDevice().setValue(value, forKey: "orientation")
}

0 个答案:

没有答案