草庐IT

ios - preferredInterfaceOrientationForPresentation 必须返回支持的界面方向

coder 2023-07-24 原文

此错误没有意义,因为首选方向 UIInterfaceOrientationLandscapeRight 由支持的方向返回

//iOS6

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft);
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}

错误:

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'

最佳答案

您的代码应如下所示:

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}

此外,请确保在您的 Info.plist 中为您的应用设置了正确的方向,因为您从 supportedInterfaceOrientations 返回的内容与 Info 相交。 plist,如果它找不到一个常见的,那么你会得到那个错误。

关于ios - preferredInterfaceOrientationForPresentation 必须返回支持的界面方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12690963/

有关ios - preferredInterfaceOrientationForPresentation 必须返回支持的界面方向的更多相关文章

随机推荐