gpt4 book ai didi

ios - 如何从相机 View 访问图库?

转载 作者:行者123 更新时间:2023-11-30 12:54:00 25 4
gpt4 key购买 nike

我正在寻找允许用户从相机 View 访问图片库的方法。

默认情况下,必须显式设置 UIImagePickerController 的源类型

self.myPickerController.sourceType = UIImagePickerControllerSourceType.camera

有什么办法可以像原生ios相机应用程序那样制作它吗?注意左下角的小图片

enter image description here

最佳答案

您可以向用户提供两个选项,并允许他们从相册中选择照片或使用相机拍照

        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];
}

关于ios - 如何从相机 View 访问图库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40634233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com