自从将我的设备更新到 6.1 后,我在尝试显示 UIImagePickerController 时遇到了崩溃。我只使用纵向。
迷恋;撞车;崩溃:
原因:*由于未捕获的异常“UIApplicationInvalidInterfaceOrientation”而终止应用程序,原因:“preferredInterfaceOrientationForPresentation 必须返回受支持的界面方向!”
这是我调用 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;
}