我正在寻找允许用户从相机视图访问图库的方法。
默认情况下,必须明确设置UIImagePickerController
self.myPickerController.sourceType = UIImagePickerControllerSourceType.camera
有没有办法像在原生ios相机应用程序中那样制作它?注意左下角的小图片
答案 0 :(得分:0)
您可以向用户提供两个选项,允许他们从相册中选择照片或使用相机拍照
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];
}