允许使用UIImagePickerController捕获照片,直到单击取消按钮

时间:2012-07-16 09:57:45

标签: ios camera uiimagepickercontroller photo

我正在实现相机功能,我需要允许用户拍摄他们喜欢的照片并存储它们。我能够做到这一点,但一次只能拍一张照片! USer必须再次点击takePhoto按钮打开相机并拍摄照片。我试图在照片保存后不解雇UIImagePickerController但它不起作用!请参阅我的以下代码。有人可以告诉我如何让用户继续拍照,直到他们点击UIImagePickerController上的取消按钮。感谢。

- (IBAction)takePhoto:(id)sender 
{

    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
        [self presentModalViewController:imagePicker animated:YES];
    } 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];

    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) 
    {
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
        NSData *imageData = UIImageJPEGRepresentation(image, 1);
       [imageData writeToFile:[delegate filePath:imageName] atomically:YES];
    }

    [picker dismissModalViewControllerAnimated:YES]; --> If I remove this then Camera stays open but Photo click button gets disabled! If I don't remove this it dismiss the camera.

}

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

1 个答案:

答案 0 :(得分:0)

看看this主题,它可能会帮助您找到您正在寻找的内容。