ViewControllerA以模态方式呈现ViewControllerB。
ViewControllerA应为纵向方向。
ViewControllerB应该是LandscapeRight方向。
我这样做: 的 ViewControllerA :
override func shouldAutorotate() -> Bool {
return false
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Portrait
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return UIInterfaceOrientation.Portrait
}
ViewControllerB
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return UIInterfaceOrientation.LandscapeRight
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.LandscapeRight
}
它有效,但当我关闭ViewControllerB时,ViewControllerA也变为LandscapeRight。 怎么解决? THX。
解:
编辑AppDelegete文件。
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
if self.window?.rootViewController?.presentedViewController is ViewControllerB {
let secondController = self.window!.rootViewController!.presentedViewController as! ViewControllerB
if secondController.isPresented {
return UIInterfaceOrientationMask.LandscapeRight;
} else {
return UIInterfaceOrientationMask.Portrait;
}
} else {
return UIInterfaceOrientationMask.Portrait;
}
}
答案 0 :(得分:1)
您需要在 ViewControllerA 中允许自动旋转,因为在 ViewControllerB 解雇后需要返回纵向模式。它稍后不会自动旋转,因为您在此屏幕上仅允许纵向方向。
解决方案是:
override func shouldAutorotate() -> Bool {
return true
}