嗨我想停止在我的项目中的视图控制器之一的自动旋转。在下面的快照, 禁用UINavigationController和UIViewController在Swift 4中的屏幕方向
我有一个开始UINavigationController
,然后UIViewController
。我已经实现下面的代码以停止自转:
extension UINavigationController {
override open var shouldAutorotate: Bool {
get {
return false
}
}
override open var supportedInterfaceOrientations: UIInterfaceOrientationMask{
get {
return UIInterfaceOrientationMask.landscape
}
}}
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override open var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask
{
return .landscape
}
}
但上面的代码似乎并没有打电话,没有服用任何影响。我正在使用Xcode 9
和swift 4.0
。 任何建议,将不胜感激。
问候, NEENA
你改变你的'Info.plist'添加'UISupportedInterfaceOrientations'? –
如果我将更改info.plist,那么它将为整个应用程序,我猜想,但我希望在某些视图控制器中的这种行为不是遍布整个应用程序。 – neena
'UISupportedInterfaceOrientations':指定应用程序支持的界面方向。 –