【发布时间】:2014-08-18 09:40:37
【问题描述】:
我正在使用 UIImagePickerController 拍照并保存到照片库。当我启动选择器时,它有拍照按钮和拍照后取消按钮,它显示 2 个按钮 Retake & use,如果我使用,使用按钮,然后只将图像保存到相册,但保存后我无法转到上一页或关闭选择器。
-(void)takepicture:(id)sender{
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker.delegate = self;
// Show image picker
[self presentModalViewController:imagePicker animated:YES];
// [self performSelector:@selector(onTimer_Loadpicture:) withObject:nil afterDelay:0.5];
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// Save image
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
// UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
[picker release];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissModalViewControllerAnimated:YES];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error)
alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
else // All is well
alert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Image saved to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
[self performSelector:@selector(onTimer_Loadpicture:) withObject:nil afterDelay:0.5];
}
【问题讨论】:
-
你没有关闭 imagePickerController 中的视图控制器:didFinishPickingMediaWithInfo:
-
你的意思是我需要添加 [self dismissModalViewControllerAnimated:YES];?
-
是的,您需要在用户拍照后关闭视图。
-
你可能还需要在 image:didFinishSavingWithError:contextInfo:
标签: ios objective-c uiimagepickercontroller