我有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控制器中我有:
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
使用ios 6运行正常但是现在在xcode / ios7中引起了问题 . 现在,即使我正在解雇Y并在横向模式下回到X,我还是设置为更喜欢肖像,所以它不应该只是强制纵向模式而不管我是否拥有横向设备?
2 回答
在解除子viewController之前添加这个:
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@“orientation”];
假设你的父母是肖像
在
shouldAutorotate
方法中返回YES
. 也许你一直在错误的视图控制器中这样做 .