【发布时间】:2019-06-03 04:47:51
【问题描述】:
我需要在单视图控制器中支持方向
我尝试但没有成功。现在在整个应用程序中定位。
override func viewDidLoad() {
super.viewDidLoad()
self.lockOrientation()
}
func lockOrientation() {
let orientationValue = UIInterfaceOrientation.portrait.rawValue
UIDevice.current.setValue(orientationValue, forKey: "orientation")
}
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .portrait
}
【问题讨论】:
-
UIDevice行是个坏主意。这是一场等待发生的崩溃。 -
@rmaddy 感谢您的评论,您能否提供运行良好的示例代码,您有什么解决方案吗?