MaT*_*TTP 6 uiviewcontroller uiimagepickercontroller ipad ios
我使用iOS 6.0在iPad 4上工作.
我有一个带有以下init的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;
}
Run Code Online (Sandbox Code Playgroud)
我实现了以下UIPickerControllerDelegate方法来dimiss MyPickerController:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
好吧,我有另一个视图控制器显示模态FormSheetStyle,当我点击一个按钮,我想MyPickerController用以下代码显示:
MyPickerController * pickerVC = [[MyPickerController alloc] init];
[self presentViewController:pickerVC animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
在我的AppDelegate中我有以下方法:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return (NSUInteger)[application supportedInterfaceOrientationsForWindow:window] | (1<<UIInterfaceOrientationPortrait);
}
Run Code Online (Sandbox Code Playgroud)
当我敲击取消按钮UIIMagePicker进入MyPickerController,并出现以下错误的应用程序崩溃:
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!
Run Code Online (Sandbox Code Playgroud)
阅读stackoverflow上的相关问题,我还创建了以下UIImagePickerController类:
@implementation UIImagePickerController (NonRotating)
- (BOOL)shouldAutorotate
{
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskPortrait;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
@end
Run Code Online (Sandbox Code Playgroud)
谢谢!
尝试这样做..
如果您的视图控制器位于 UINavigationController 内,则应该使用此类别作为导航控制器:
@implementation UINavigationController (autorotate)
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationMaskPortrait;
}
@end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
761 次 |
| 最近记录: |