对于我的项目,设备方向为portrair
。但只有一个视图控制器在view did load
,没有rotating
电话时,我想像“左侧风景”一样旋转视图。我试过以下。在我看来确实加载了,
override func viewDidLoad() {
super.viewDidLoad()
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
我用这种方法......
override func shouldAutorotate() -> Bool {
return true
}
但没什么好开心的。然后我也用上面的方法使用以下方法。
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.All
}
然后它导致崩溃。并没有什么对我有用。任何想法如何做到这一点。
这是我的项目设备方向设置看起来像......
我该怎么办?希望你的帮助。
答案 0 :(得分:0)
执行所需操作的最佳方法是在应用设置中allow all Orientations。
然后将"应自动调整" 变量设置为true il所有viewControllers
override func shouldAutorotate() -> Bool {
return true
}
然后根据 ViewContoller
设置 supportedInterfaceOrientationsoverride func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Landscape
}
override func shouldAutorotate() -> Bool {
return false
}
import UIKit
class PortraitViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//Here the viewController will appear in Portrait (Also all subclass of it)
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Portrait
}
override func shouldAutorotate() -> Bool {
return false
}
}
class LandscapeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//Here the viewController will appear in Landscape (Also all subclass of it)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Landscape
}
override func shouldAutorotate() -> Bool {
return true
}
}