使用Swift在一个ViewController中强制横向模式 [英] Force landscape mode in one ViewController using Swift

查看:528
本文介绍了使用Swift在一个ViewController中强制横向模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的应用程序中仅在横向模式下强制使用一个视图,
我正在调用

I am trying to force only one view in my application on landscape mode, I am calling

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

override func supportedInterfaceOrientations() -> Int {
    print("supportedInterfaceOrientations")
    return Int(UIInterfaceOrientationMask.LandscapeLeft.rawValue)
}

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

视图在纵向模式,并在我更改设备方向时保持旋转。

永远不会调用shouldAutorotate。

任何帮助都将受到赞赏。

The view is launched in the portrait mode, and keep rotating when I change the device orientation.
The shouldAutorotate is never called.
Any help would be appreciated.

推荐答案

它可能对其他人有用,我找到了一种强制视图以横向模式启动的方法:

It may be useful for others, I found a way to force the view to launch in landscape mode:

将它放在viewDidLoad()中:

Put this in the viewDidLoad():

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

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

这篇关于使用Swift在一个ViewController中强制横向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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