我正在尝试用iPhone拍摄基本照片。我使用以下代码显示相机:
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose picture or
// movie capture, if both are available:
cameraUI.mediaTypes =
[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
[controller presentModalViewController: cameraUI animated: YES];
return YES;
}
这很好用,但是如果我定义了处理函数:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
}
按下“使用”按钮后,imagePicker控件会冻结。它不会崩溃,不会抛出任何异常,代码正在做某事,但在屏幕上我只看到了冻结的imagePicker控件。即使处理程序为空,控件也会冻结。如果我删除处理程序,相机会正常消失,并显示相机被激活的视图... 我错过了一些必要的东西吗?
更新: 我尝试将图像分配给UIImageView,代码执行,退出函数,就是这样,相机保留在屏幕上:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
UIImage* original =[info objectForKey:@"UIImagePickerControllerOriginalImage"];
[[self imgWLItemImage] setImage:[UIImage imageWithCGImage:original.CGImage scale:0.25 orientation:original.imageOrientation]];
}
答案 0 :(得分:12)
试试这个&amp;检查:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
UIImage* original =[info objectForKey:@"UIImagePickerControllerOriginalImage"];
[[self imgWLItemImage] setImage:[UIImage imageWithCGImage:original.CGImage scale:0.25 orientation:original.imageOrientation]];
}