我有一个 UIViewController
(称为 B),我想以横向显示(强制)它。所有其他 UIViewControllers
均以纵向模式显示。在我的项目设置中,只选择了纵向模式。
我的问题是,当我从 B 回到 A 时,它停留在横向模式。
在 AppDelegate 内部:
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if #available(iOS 10.0, *) {
if self.window?.rootViewController?.presentedViewController is CheckImageCameraViewController {
return UIInterfaceOrientationMask.landscapeRight
} else {
return UIInterfaceOrientationMask.portrait
}
} else {
// Fallback on earlier versions
}
return UIInterfaceOrientationMask.portrait
}
在 Controller A中;
let controllerB = ControllerB()
self.present(controllerB,animated:true,completion:nil)
在 Controller B中;
override func viewDidLoad() {
super.viewDidLoad()
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
}
func closeButtonTapped(){
self.dismiss()
}
编辑: 当它在 A 上时,如果我移动手机以改变方向。它看起来是纵向的。
最佳答案
重写 A 中的 viewWillAppear()
,检查方向并采取适当的操作。
关于ios - Dismiss 后父 UIViewController 不会改变方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53320851/