【问题标题】:How to access gallery from the camera view?如何从相机视图访问画廊?
【发布时间】:2016-11-16 14:08:58
【问题描述】:
我正在寻找允许用户从相机视图访问图片库的方法。
默认情况下,必须为UIImagePickerController 显式设置源类型
self.myPickerController.sourceType = UIImagePickerControllerSourceType.camera
有没有办法像原生 ios 相机应用程序那样制作它?注意左下角的小图片
【问题讨论】:
标签:
ios
swift
swift3
uiimagepickercontroller
【解决方案1】:
您可以向用户显示两个选项,并允许他们从相册中选择照片或使用相机拍照
if (optionId == 1) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, kUTTypeImage, nil];
imagePicker.allowsEditing = NO;
imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:imagePicker animated:YES completion:nil];
}else {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"Camera not supported."] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alertView show];
}
}else if (optionId == 2) {
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
if ( [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, kUTTypeImage, nil];
imagePicker.allowsEditing = NO;
imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:imagePicker animated:YES completion:nil];
}