我有一个嵌入在导航 Controller 中的 View Controller ,如下所示:
导航 Controller 是一个自定义子类,如下所示
class SNNAvigationViewController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override var shouldAutorotate: Bool {
return false
}
}
正如你所看到的,我重写了 shouldAutorotate 来表示 false。另外,在相机 View Controller 中我有:
class CameraViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, CameraButtonDelegate {
...
override var shouldAutorotate: Bool {
return false
}
...
}
但是不幸的是,当我转动手机时, View 仍然自动旋转。我在这里缺少什么?
最佳答案
您是否尝试过在导航 Controller 中添加此代码?
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
(如果您想要自然的肖像)。
关于ios - 如何防止嵌入导航 Controller 的 View Controller 中的自动旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51370214/