UIImagePickerController和接口方向

时间:2013-11-10 06:03:06

标签: ios objective-c

我的应用程序是通用的。 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>

App Delegate

- (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提供的视图控制器呈现的

3 个答案:

答案 0 :(得分:0)

UIImagePickerController类别中使用

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

答案 1 :(得分:0)

原来你必须在iPad上的popover中呈现UIImagePickerController。

答案 2 :(得分:0)

UIImagePickerController类仅支持纵向模式。见Apple docs