[英]if app device orientation is portrait how to set force landscape only for one view constroller in ios, swift 2.3
for my project, device orientation is portrair
. 对于我的项目,设备方向为
portrair
。 but only for one view controller when view did load
, without rotating
the phone, I want to rotate the view like 'landscape left`. 但仅适用于一个视图控制器,当
view did load
,不rotating
手机,我想像“向左横向移动”那样旋转视图。 I tried followings . 我尝试了以下方法。 in my view did load,
我认为确实加载了
override func viewDidLoad() {
super.viewDidLoad()
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
and I used this method ... 我用这种方法...
override func shouldAutorotate() -> Bool {
return true
}
but nothing happned. 但什么也没发生。 then I use following method too with above methods.
然后我也将以下方法与上述方法一起使用。
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.All
}
then it cause for a crash. 那么会导致崩溃。 and nothing worked for me.
对我没有任何作用。 any idea how to do that.
任何想法如何做到这一点。
this is my project device orientation settings looks like ... 这是我的项目设备方向设置看起来像...
how can I do this. 我怎样才能做到这一点。 hope your help with this.
希望您对此有所帮助。
The best way to do what you want is to allow all Orientations in your app settings. 进行所需操作的最佳方法是在应用程序设置中允许所有方向 。
Then set the "should autorotate" variable to true il all your viewControllers 然后将“所有的viewControllers ”设置为“ should autorotate”变量为true
override func shouldAutorotate() -> Bool {
return true
}
Then set the supportedInterfaceOrientations depending of your ViewContoller 然后根据您的ViewContoller设置supportedInterfaceOrientations
override 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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.