UIImagePickerController自定义FlashMode按钮在IOS 10上不起作用(Swift) [英] UIImagePickerController custom FlashMode button is not working on IOS 10 (swift)

查看:287
本文介绍了UIImagePickerController自定义FlashMode按钮在IOS 10上不起作用(Swift)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I know that a question of this type is already asked but I Debugged it in bit detail, and i came to this point that when i switched this flag off

   self.picker.showsCameraControls = false

然后自定义闪光灯按钮不响应,但是如果我将标志更改为

then the custom flash button doesn't respond but if I'll change the flag to

   self.picker.showsCameraControls = true

然后我的自定义闪光灯按钮响应确定,我已经检查了所有委托和标志,但是我无法指出该错误,无论是在我的代码中还是在IOS 10版本中(如果在我的代码中)显示相机控件时,为什么我的自定义闪光灯按钮会更改闪光灯状态并能正常工作. 这是我的代码,用于更好地理解:

then my custom flash button responding OK, I have check all the delegates and flags but I am not able to pin point the bug, either it is in my code or it is in IOS 10 version, if its in my code then on showing camera controls why my custom flash button changes state of flash and work fine. here is my code for better understanding:

   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. 如果没有解决此问题的方法,请提出任何建议. 谢谢

In short my custom flashmode button is not working on cameraoverlayview. if there is no solution to this problem then please suggest any hack. thanks

推荐答案

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

I've solved my problem with a clumsy hack,

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

它的速度足够快,不会干扰用户的显示和隐藏控件. 可行!

It is fast enough to not disturb user with the showing and hiding controls. It Worked!

这篇关于UIImagePickerController自定义FlashMode按钮在IOS 10上不起作用(Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆