我有一个UITabBarViewController
纵向模式,我按modalViewController
横向模式。当我推动模式时,旋转变为横向,但是当我关闭它时,方向保持在横向而不是恢复为纵向。
代码:
aCustomUINavigationController
用于横向模式:
- (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 中设置了两个方向。