1

我知道已经问过这种类型的问题,但是我对其进行了详细的调试,并且当我关闭此标志时,我得出了这一点

   self.picker.showsCameraControls = false

那么自定义闪光灯按钮没有响应,但如果我将标志更改为

   self.picker.showsCameraControls = true

然后我的自定义闪光灯按钮响应确定,我检查了所有代表和标志,但我无法确定错误,无论是在我的代码中还是在 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()
    }
}

简而言之,我的自定义 flashmode 按钮在 cameraoverlayview 上不起作用。如果这个问题没有解决方案,那么请提出任何黑客建议。谢谢

4

1 回答 1

4

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

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

它足够快,不会干扰用户的显示和隐藏控件。有效!

于 2016-11-07T06:49:57.663 回答