UIImagePickerController InterfaceOrientation 崩溃 [英] UIImagePickerController InterfaceOrientation Crash

查看:24
本文介绍了UIImagePickerController InterfaceOrientation 崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从将我的设备更新到 6.1 后,我在尝试显示 UIImagePickerController 时遇到了崩溃.我只使用纵向.

Ever since updating my device to 6.1, I'm getting a crash when trying to show the UIImagePickerController. I only use Portrait orientation.

崩溃:

原因:* 由于未捕获的异常UIApplicationInvalidInterfaceOrientation"而终止应用,原因:preferredInterfaceOrientationForPresentation 必须返回支持的界面方向!"

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

这里是我调用 UIImagePickerController 的地方:

Here is where I call the 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 的视图控制器中:

I've added these methods to the view controller where the UIImagePickerController is added:

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

推荐答案

为了解决这个问题,我做了一个分类如下:

To fix the issue, I made a category as follows:

我创建了一个新的objective-c类,UIImagePickerController+NonRotating"

I created a new objective-c class, "UIImagePickerController+NonRotating"

在头文件(UIImagePickerController+NonRotating.h)中:

In the header file (UIImagePickerController+NonRotating.h):

#import <Foundation/Foundation.h>

@interface UIImagePickerController (NonRotating)

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

@end

在实现文件(UIImagePickerController+NonRotating.m)中:

In the implementation file (UIImagePickerController+NonRotating.m):

#import "UIImagePickerController+NonRotating.h"

@implementation UIImagePickerController (NonRotating)

- (BOOL)shouldAutorotate {
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

@end

您当然可以修改它,但您认为合适 - 使其自动旋转并返回多个支持的方向等.

You could of course modify this however you see fit -- making it autorotate and returning multiple supported orientations, etc.

这篇关于UIImagePickerController InterfaceOrientation 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆