簡體   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