UIImagePickerController界面方向崩溃

4

自从我把我的设备更新到6.1版本后,在尝试显示UIImagePickerController时,我遇到了崩溃问题。我只使用纵向方向。

崩溃信息:

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

以下是我调用UIImagePickerController的位置:

if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    //The device cannot make pictures
    [PMAlertDialog showWithTitle:NSLocalizedString(@"incompatibleDeviceDialogTitle", nil) message:NSLocalizedString(@"incompatibleDeviceDialogMessage", nil) andButtonTitle:NSLocalizedString(@"okButtonTitle", nil)];
    return;
}

if (_imagePicker == nil)
{
    _imagePicker = [[UIImagePickerController alloc] init];
    _imagePicker.delegate = self;
}

_imagePicker.allowsEditing = NO;
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];

[self presentModalViewController:_imagePicker animated:YES];

我已经将这些方法添加到包含UIImagePickerController的视图控制器中:

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
1个回答

2
为了解决这个问题,我创建了一个以下类别:
我创建了一个新的Objective-C类,“UIImagePickerController+NonRotating”。
在头文件(UIImagePickerController+NonRotating.h)中:
#import <Foundation/Foundation.h>

@interface UIImagePickerController (NonRotating)

- (BOOL)shouldAutorotate;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;

@end

在实现文件中(UIImagePickerController+NonRotating.m):
#import "UIImagePickerController+NonRotating.h"

@implementation UIImagePickerController (NonRotating)

- (BOOL)shouldAutorotate {
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

@end

当然,你可以按照自己的想法进行修改--使其自动旋转并返回多个支持的方向等等。

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