【发布时间】:2012-09-22 13:03:35
【问题描述】:
我在纵向模式下有一个UITabBarViewController,我在横向模式下推送一个modalViewController。当我按下模式时,旋转变为横向,但当我关闭它时,方向保持在横向而不是恢复为纵向。
代码:
CustomUINavigationController 用于横向模式:
- (BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
uitabbar 控制器
- (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 中设置了两个方向。
【问题讨论】: