【发布时间】:2014-05-08 20:13:10
【问题描述】:
我有 viewcontroller X 和 viewcontroller Y。
viewController X 呈现 Y,Viewcontroller X 只能以纵向模式显示,但 Y 可以旋转到它想要的任何模式。
当我在横向模式下关闭 viewController Y 时,我收到以下错误。 排队:
[self dismissViewControllerAnimated:YES completion:nil];
错误: 由于未捕获的异常“UIApplicationInvalidInterfaceOrientation”而终止应用,原因:“preferredInterfaceOrientationForPresentation 必须返回受支持的界面方向!”
在 X 控制器中,我有:
-(BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
在 Y 控制器中我有:
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
这在 ios 6 上运行良好,但现在在 xcode /ios7 中导致问题。现在,即使我在横向模式下关闭 Y 并返回 X,我也将其设置为更喜欢纵向,所以它不应该只强制纵向模式,而不管我的设备是否处于横向模式?
【问题讨论】:
-
我不确定它是否会起作用,我想你已经尝试过了。但我建议将
shouldAutorotate中的shouldAutorotate上的NO更改为YESX -
不是这个,但我没试过。我尝试了同样的结果。原来我正在查看错误的文件,因为这是在选项卡视图控制器中,它正在寻找加载的最后一个视图的支持方向我添加了首选方法,它现在可以工作了。
标签: ios iphone objective-c uiviewcontroller