如何在UIImagePickerController(Camera)中以编程方式触发“完成”功能?

时间:2017-02-18 17:18:04

标签: ios

我目前正在我的应用程序中使用UIImagePickerController来利用本机iOS相机功能。

但是,我想要:

1)以某种方式以编程方式触发“完成”按钮后面的方法,这样我的用户就不必

2)跳过相机的图像预览而不会丢失UIImagePickerController提供的任何现有UI功能(如切换闪光灯,曝光等)

使用案例:我正在使用低能量蓝牙快门按钮设备拍摄照片,而无需用手指按下屏幕上的捕捉按钮。我想也允许用户按下蓝牙按钮按下完成按钮或完全放弃完成步骤并立即返回didFinishPickingMediaWithInfo。

这有可能吗?这是我对UIImagePickerController的实现

@IBAction func presentCameraController() {
        DispatchQueue.global(qos: .userInitiated).async {
            CameraAuthorization.GetAuthorizationStatus(completion: { granted in
                if granted {
                    DispatchQueue.main.async {
                        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
                            let picker = UIImagePickerController();
                            picker.delegate = self
                            picker.sourceType = .camera

                        if let decider = UserDefaults.standard.value(forKey: "cameraFlashEnabled") as? Bool {
                            if (decider) {
                                picker.cameraFlashMode = .on
                            } else {
                                picker.cameraFlashMode = .off
                            }
                        } else {
                            picker.cameraFlashMode = .on
                        }

                        self.present(picker, animated: true, completion: nil)
                    }
                }
            } else {
                DispatchQueue.main.async {
                    let encouragement = CameraAuthorization.EncourageAccess()
                    self.present(encouragement, animated: true, completion: nil)
                }
            }
        })
    }

internal func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    let image = info[UIImagePickerControllerOriginalImage] as? UIImage

    dismiss(animated: true, completion: {
        self.selectedImage = image
        self.performSegue(withIdentifier: "segueToPhotoEditor", sender: nil)
    })
}

1 个答案:

答案 0 :(得分:0)

showsCameraControls设置为false并且(如果您希望用户点击某些内容以拍摄照片)提供您自己的拍照界面。要拍照,请致电(获取此项)takePicture