简体   繁体   中英

Allow capturing photos using UIImagePickerController until cancel button clicked

I am implementing camera functionality where I need to allow users to take photos as many they like and store them. I am able to do this but one photo at a time! USer has to click again takePhoto button to open camera and capture photo. I am trying to not dismiss UIImagePickerController after photo has been saved but it's not working! Please see my following code. Could someone please tell me how could I allow users to keep taking picture until they click cancel button on UIImagePickerController. Thanks.

- (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];
}

看一下这个线程,它可能会帮助您找到所需的内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM