我的应用程序是通用的。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 呈现的视图控制器呈现的