[英]How to rotate forcefully in my SDK VideoViewController to landscape orientation when app supports only portrait orientation in iOS Swift
[英]if app device orientation is portrait how to set force landscape only for one view constroller in ios, swift 2.3
对于我的项目,设备方向为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
}
那么会导致崩溃。 对我没有任何作用。 任何想法如何做到这一点。
这是我的项目设备方向设置看起来像...
我怎样才能做到这一点。 希望您对此有所帮助。
进行所需操作的最佳方法是在应用程序设置中允许所有方向 。
然后将“所有的viewControllers ”设置为“ should autorotate”变量为true
override func shouldAutorotate() -> Bool {
return true
}
然后根据您的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.