How to allow the user to pick a photo from his camera roll or photo library?

后端 未结 7 1580
粉色の甜心
粉色の甜心 2021-01-02 01:11

I\'m making a little photo editing app for fun. Users must select a photo from their camera roll which will then be imported for modification.

How does this generall

7条回答
  •  感情败类
    2021-01-02 01:47

    This answer relevant on physical device ONLY!

    Access Camera:

    - (void)takePhoto {
    
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    
    [self presentViewController:picker animated:YES completion:NULL];
    
    }
    

    Access Camera Roll:

    - (void)selectPhoto {
    
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    
    [self presentViewController:picker animated:YES completion:NULL];
    
    
    }
    

    Implementing the Delegate Methods of UIImagePickerController:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    self.imageView.image = chosenImage;
    
    [picker dismissViewControllerAnimated:YES completion:NULL];
    
    }
    

    And This:

    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    
    [picker dismissViewControllerAnimated:YES completion:NULL];
    
    }
    

    Also check for more info on this link

提交回复
热议问题