0

我的应用程序是通用的。iPad 只能横向(左或右);iPhone 仅是纵向的。

iPhone 的一切工作正常,但在尝试呈现 UIImagePickerController 时,我在 iPad 上遇到了以下错误。

错误

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

这是我的设置...

Info.plist(iPad 支持的方向)

<array>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>

应用代理

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if(isPad()){
        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }else{
        return UIInterfaceOrientationMaskPortrait;
    }
}

视图控制器呈现选择器

- (NSUInteger) supportedInterfaceOrientations
{
    if(isPad()){
        return UIInterfaceOrientationMaskLandscape;
    }else{
        return UIInterfaceOrientationMaskPortrait;
    }
}

-(BOOL)shouldAutorotate{
    return NO;
}

-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
if(isPad()){
    return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}else{
    return UIInterfaceOrientationPortrait;
}

}

UIImagePickerController 类别

- (NSUInteger) supportedInterfaceOrientations
{
    if(isPad()){
        return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
    }else{
        return UIInterfaceOrientationMaskPortrait;
    }
}

-(BOOL)shouldAutorotate{
    return NO;
}

-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
    if(isPad()){
        return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
    }else{
        return UIInterfaceOrientationPortrait;
    }
}

值得注意

UIImagePicker(在 iPad 中)是从 UIPopoverController 呈现的视图控制器呈现的

4

3 回答 3

0

结果你必须在 iPad 上的弹出窗口中显示 UIImagePickerController。

于 2013-11-10T06:12:14.910 回答
0

UIImagePickerController类别中使用

-(NSUInteger)supportedInterfaceOrientations {  
    if(isPad()){
        return UIInterfaceOrientationMaskLandscape;
    }
    else{
        return UIInterfaceOrientationMaskPortrait;
    }
} 
于 2013-11-10T06:06:29.770 回答
0

UIImagePickerController 类仅支持纵向模式。请参阅Apple 文档

于 2013-11-10T06:35:58.837 回答