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



我知道这种类型的问题已经被问过了,但我调试了它的位细节,我来到这一点,当我关闭这个标志

   self.picker.showsCameraControls = false

则自定义flash按钮没有响应但如果我将标志改为

   self.picker.showsCameraControls = true

然后我的自定义flash按钮响应OK,我检查了所有的委托和标志,但我无法指出错误,要么是在我的代码中,要么是在IOS 10版本中,如果它在我的代码中,那么在显示相机控制时,为什么我的自定义flash按钮会改变flash状态并正常工作。下面是我的代码,以便更好地理解:

   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上工作。如果没有解决这个问题,请建议任何hack。由于

我已经用一个笨拙的hack解决了我的问题,

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

它足够快,不会打扰用户与显示和隐藏控件。它工作!

相关内容

  • 没有找到相关文章

最新更新