There are tons of examples on how to add a button to access the photo library from the camera view, but I can't seem to find anything about doing it the other way around.
In my app the primary source of the images would be the library, but I also want to let the users use the camera if they really want to. If possible I would like to avoid the additional step of presenting an action sheet with the two options (library and camera) or some similar solution. Also, I would prefer not to have two dedicated buttons.
I use this code:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
self.imgPicker = [[UIImagePickerController alloc] init];
if(buttonIndex == 0) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imgPicker.allowsEditing = NO;
self.imgPicker.delegate = self;
self.imgPicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
}
}
if(buttonIndex == 1) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imgPicker.allowsEditing = NO;
self.imgPicker.delegate = self;
}
}
[self performSelector:@selector(showPicker) withObject:self afterDelay:0.6f];
}
- (void)showPicker {
[self presentModalViewController:self.imgPicker animated: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.