我有 viewcontroller X 和 viewcontroller Y。
viewController X 展示 Y,Viewcontroller X 应该只以纵向模式显示,但 Y 可以旋转到它想要的任何模式。
当我在横向模式下关闭 viewController Y 时,出现以下错误。 行内:
[self dismissViewControllerAnimated:YES completion:nil];
错误: 由于未捕获的异常“UIApplicationInvalidInterfaceOrientation”而终止应用程序,原因:“preferredInterfaceOrientationForPresentation 必须返回支持的界面方向!”
在 X Controller 中,我有:
-(BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
在 Y Controller 中我有:
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
这在 ios 6 上运行正常,但现在在 xcode/ios7 中导致问题。现在,即使我在横向模式下关闭 Y 并返回 X,我将它设置为更喜欢纵向模式,所以它不应该强制纵向模式而不管我的设备处于横向模式吗?
最佳答案
在关闭子 viewController 之前添加:
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"方向"];
假设你的 parent 是纵向的
关于ios - 关闭纵向 View Controller 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23551608/