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 我有以下 totation 方法:

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

当我点击UIIMagePickerintoMyPickerController的取消按钮时,应用程序崩溃并出现以下错误:

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

谢谢!

4

1 回答 1

2

尝试这样做..

如果您的视图控制器位于 UINavigationController 中,则应将此类别用于导航控制器:

@implementation UINavigationController (autorotate)

- (NSUInteger)supportedInterfaceOrientations{
      return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
      return UIInterfaceOrientationMaskPortrait;
}


@end
于 2013-01-21T10:55:22.487 回答