我在装有 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);
}
当我点击UIIMagePicker
intoMyPickerController
的取消按钮时,应用程序崩溃并出现以下错误:
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
谢谢!