ViewControllerA представляет ViewControllerB modally.iOS - Принудительная ориентация устройства, если контроллер вида представлен модально
ViewControllerA должен быть портретной ориентации.
ViewControllerB должен быть ориентирован на ландшафт.
я: 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;
}
}
Ваше решение является правильным, но он будет получать очень сложно, если вы будете иметь больше ViewControllers в разных направлениях. Вы можете попробовать мое решение, оно работает в моем сценарии. – KlimczakM