我有一個UITabBarViewController
肖像模式,我推動modalViewController
橫向。當我按下模式時,旋轉會變成風景,但是當我解散它時,方向會保持在風景中而不是恢復爲人像。iOS 6恢復方向後關閉ModalViewController
代碼:
一個CustomUINavigationController
爲風景模式:
- (BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
中的UITabBarController
- (BOOL)shouldAutorotate
{
if ([self inModal]) {
UINavigationController *nav = (UINavigationController *)self.modalViewController;
return [[nav.viewControllers lastObject] shouldAutorotate];
} else {
return NO;
}
}
-(NSUInteger)supportedInterfaceOrientations
{
if ([self inModal]) {
UINavigationController *nav = (UINavigationController *)self.modalViewController;
return [[nav.viewControllers lastObject] supportedInterfaceOrientations];
} else {
return UIInterfaceOrientationPortrait;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if ([self inModal]) {
UINavigationController *nav = (UINavigationController *)self.modalViewController;
return [[nav.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
} else {
return UIInterfaceOrientationPortrait;
}
}
- (BOOL)inModal
{
if (self.modalViewController && [self.modalViewController isKindOfClass:[UINavigationController class]]) {
return YES;
} else {
return NO;
}
}
如果我設置shouldRotate爲YES我得到一個錯誤:*終止應用程序由於未捕獲異常'UIApplicationInvalidInterfaceOrientation',原因:'支持的方向與應用程序沒有共同的方向,並且shouldAutorotate返回YES。儘管我已經在UISupportedDeviceOrientations中設置了兩個方向。