我在装有 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];
}
好吧,我有另一个 View Controller 以 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
谢谢!
最佳答案
尝试这样做..
如果您的 View Controller 在 UINavigationController 中,您应该将此类别用于导航 Controller :
@implementation UINavigationController (autorotate)
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationMaskPortrait;
}
@end
关于ios - UIIMagePickerController 在 iPad ios 6.0 上关闭时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14397242/