UIImagePickerController 自定义 FlashMode 按钮在 IOS 10 (swift) 上不起作用

UIImagePickerController custom FlashMode button is not working on IOS 10 (swift)

我知道已经有人问过这种类型的问题,但我对其进行了详细调试,当我关闭此标志时,我想到了这一点

   self.picker.showsCameraControls = false

然后自定义 flash 按钮没有响应,但如果我将标志更改为

   self.picker.showsCameraControls = true

然后我的自定义 flash 按钮响应正常,我已经检查了所有的代表和标志,但我无法查明错误,无论是在我的代码中还是在 IOS 10 版本中,如果它在我的代码中然后显示相机控制为什么我的自定义闪光灯按钮改变闪光灯状态并且工作正常。 这是我的代码,以便更好地理解:

   func configureImagePicker(){
         self.picker.delegate = self
         self.picker.allowsEditing = false
        if       UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)
    {
        self.picker.sourceType = UIImagePickerControllerSourceType.Camera
        self.picker.mediaTypes = [kUTTypeImage as String]
    }
}

  func showImagePicker(){
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){

        self.picker.sourceType = UIImagePickerControllerSourceType.Camera
        self.picker.showsCameraControls = false
        self.picker.delegateController = self
        self.picker.delegate = self
        self.picker.mediaTypes = [kUTTypeImage as String]
        self.picker.allowsEditing = false


        if let cameraOverlay = self.picker.cameraOverlayView {

            self.createCamerOverlay(cameraOverlay.frame)
            self.picker.cameraOverlayView = self.overlayView


            self.presentViewController(self.picker, animated: false, completion: {
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(Double(0.5)*Double(NSEC_PER_SEC))), dispatch_get_main_queue(), {
                    if self.picker.cameraDevice == UIImagePickerControllerCameraDevice.Rear && UIImagePickerController.isFlashAvailableForCameraDevice(UIImagePickerControllerCameraDevice.Rear)
                    {
                        if Float.init(UIDevice.currentDevice().systemVersion) < 11.0
                        {
                            switch(Global.shared.currenFlashOption)
                            {
                                case .FlashOff:
                                    self.picker.cameraFlashMode = .Off
                                    let flashImage = UIImage(named: "btn-flash-off")
                                    self.flashButton.setImage(flashImage, forState: UIControlState.Normal)
                                    self.flashButton.setImage(flashImage, forState: UIControlState.Highlighted)
                                case .FlashAuto:
                                    self.picker.cameraFlashMode = .Auto
                                    let flashImage = UIImage(named: "btn-flash")
                                    self.flashButton.setImage(flashImage, forState: UIControlState.Normal)
                                    self.flashButton.setImage(flashImage, forState: UIControlState.Highlighted)
                                case .FlashOn:
                                    self.picker.cameraFlashMode = .On
                                    let flashImage = UIImage(named: "btn-flash-on")
                                    self.flashButton.setImage(flashImage, forState: UIControlState.Normal)
                                    self.flashButton.setImage(flashImage, forState: UIControlState.Highlighted)
                            }
                        }
                        else
                        {
                            self.picker.cameraFlashMode = UIImagePickerControllerCameraFlashMode.On

                        }
                    }
                });
            });

        } else {
            print("Camera overlay frame not found. So did not present the controller.")
        }
    }
    else{
        let alert = UIAlertView(title: "Error", message: "Camera Not Available", delegate: nil, cancelButtonTitle: "Cancel")
        alert.show()
    }
}

简而言之,我的自定义闪光灯模式按钮在 cameraoverlayview 上不起作用。 如果没有解决此问题的方法,请提出任何建议。 谢谢

我用笨拙的技巧解决了我的问题,

 self.picker.showsCameraControls = true
 self.picker.cameraFlashMode = .On
 self.picker.showsCameraControls = false

它的速度足够快,不会因为显示和隐藏控件而打扰用户。 成功了!