繁体   English   中英

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

[英]Allow capturing photos using UIImagePickerController until cancel button clicked

我正在实现相机功能,我需要允许用户拍摄任意数量的照片并进行存储。 我能够做到这一点,但一次只能一张照片! 用户必须再次单击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];
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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