此错误没有意义,因为支持的方向
返回首选方向UIInterfaceOrientationLandscapeRight
//iOS6
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
错误:
由于未捕获的异常而终止应用 'UIApplicationInvalidInterfaceOrientation',原因: 'preferredInterfaceOrientationForPresentation必须返回支持的 界面方向!'
答案 0 :(得分:55)
您的代码应如下所示:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
此外,请确保在Info.plist
中为您的应用设置了正确的方向,因为您从supportedInterfaceOrientations
返回的内容与Info.plist
相交,如果找不到常见的那样你就会得到那个错误。
答案 1 :(得分:13)
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
对我来说最简单的方法是设置Info.plist
如果您想支持iOS 5,请在视图控制器中使用此代码。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
答案 2 :(得分:9)
这些是supportedInterfaceOrientations
的错误枚举。你需要使用UIInterfaceOrientationMaskLandscapeLeft
等(注意中间的单词掩码)
答案 3 :(得分:1)
来自文档:
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}
请注意,正确的方向是“面具”! 你试过这个吗?