【问题标题】: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];
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-29
    • 1970-01-01
    • 2012-11-07
    • 2017-03-03
    • 2021-10-30
    相关资源
    最近更新 更多