在iPad中,UIImagePickerController必须通过UIPopoverController呈现 [英] Exception in iPad, UIImagePickerController must be presented via UIPopoverController

查看:113
本文介绍了在iPad中,UIImagePickerController必须通过UIPopoverController呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从相机创建了一个捕获图像的应用程序。这是我的代码

I have created an application for capture image from camera. This is my code

 -(IBAction) showCameraUI {
    BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
    UIImagePickerController* picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = hasCamera ? UIImagePickerControllerSourceTypeCamera :    UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];
}

并实现此委托方法以获取捕获的图像

And implemented this delegate method for get the captured image

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissModalViewControllerAnimated:YES];
    UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
    UIImage *yourImageView = image;
}

如果用户取消控制器,则实施此方法

Implemented this method if user cancel the controller

- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
{
    [picker dismissModalViewControllerAnimated:YES];
}

但是它显示了这个例外。有没有人知道为什么它在执行函数showCameraUI的最后一行后显示这样的异常。

But it shows this exception. Does anyone have any idea why it is showing such exception after executing last line of function showCameraUI.

UIStatusBarStyleBlackTranslucent is not available on this device. 2013-02-07 
10:06:06.976 CaptureImage[460:c07] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: 'On iPad, UIImagePickerController must be 
presented via UIPopoverController'


推荐答案

关于异常,错误消息非常清楚。 在iPad上,必须通过UIPopoverController呈现UIImagePickerController对于iPad,您应该将它呈现在 UIPopoverController 中,而不是使用 [self presentModalViewController:picker animated:YES]; 。这应解决问题。

Regarding the exception, the error message is very clear. "On iPad, UIImagePickerController must be presented via UIPopoverController" For iPad, you should present it in a UIPopoverController instead of using [self presentModalViewController:picker animated:YES];. This should fix the issue.

例如: -

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
    [popover presentPopoverFromRect:self.view.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    self.popover = popover;
} else {
    [self presentModalViewController:picker animated:YES];
}

编辑如@rmaddy所述,相机可以模态呈现。当 sourceType UIImagePickerControllerSourceTypePhotoLibrary 时,以上内容适用。

As mentioned by @rmaddy, camera can be presented modally. The above is applicable when sourceType is UIImagePickerControllerSourceTypePhotoLibrary.

这篇关于在iPad中,UIImagePickerController必须通过UIPopoverController呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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