已经创建了一个从相机捕获图像的应用程序。这是我的代码
-(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];
}
并实现了这个委托方法来获取捕获的图像
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *yourImageView = image;
}
如果用户取消控制器,则实现此方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
但它显示了这个例外。有谁知道为什么在执行最后一行函数 showCameraUI 后会显示这样的异常。
UIStatusBarStyleBlackTranslucent 在此设备上不可用。2013-02-07 10:06:06.976 CaptureImage [460:c07] *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“在 iPad 上,UIImagePickerController 必须通过 UIPopoverController 呈现”