UIIMagePickerController在iPad ios 6.0上关闭时崩溃

6

我使用iOS 6.0系统的iPad 4。

我有一个ViewController(MyPickerController),其初始化如下:

- (id)init
{
    self = [super init];
    if (self) {
        _picker = [[UIImagePickerController alloc] init];
        _picker.delegate = self;
        _picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self.view addSubview:_picker.view];
    }
    return self;
}

我实现了以下的UIPickerControllerDelegate方法来关闭MyPickerController:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

我有另一个视图控制器以FormSheetStyle模态显示,当我点击一个按钮时,我想使用以下代码显示MyPickerController

MyPickerController * pickerVC = [[MyPickerController alloc] init];
[self presentViewController:pickerVC animated:YES completion:nil];

在我的AppDelegate中,我有以下旋转方法:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    
    return (NSUInteger)[application supportedInterfaceOrientationsForWindow:window] | (1<<UIInterfaceOrientationPortrait);
    
}

当我点击MyPickerController中的取消按钮时,应用程序会崩溃,并显示以下错误:

UIIMagePicker


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

在stackoverflow上阅读相关问题后,我还创建了以下UIImagePickerController类别:

@implementation UIImagePickerController (NonRotating)

- (BOOL)shouldAutorotate
{
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

@end

谢谢!


为什么要将Picker的视图添加为您视图的子视图? - oiledCode
1个回答

2

尝试这样做...

如果您的视图控制器在UINavigationController中,您应该使用这个类别来处理navigationcontroller:

@implementation UINavigationController (autorotate)

- (NSUInteger)supportedInterfaceOrientations{
      return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
      return UIInterfaceOrientationMaskPortrait;
}


@end

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接