我知道这个类型的问题已经被问过了,但是我稍微调试了一下这个问题,而且当我把这个标志关掉时,我发现了这个问题
self.picker.showsCameraControls = false
然后自定义flash按钮没有响应,但如果我将标志更改为
self.picker.showsCameraControls = true
然后我的自定义Flash按钮响应OK,我已检查所有代理和标志但我无法确定错误,无论是在我的代码中还是在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上运行。 如果这个问题没有解决方案,请建议任何黑客攻击。 感谢
答案 0 :(得分:4)
我用笨拙的黑客解决了我的问题,
self.picker.showsCameraControls = true
self.picker.cameraFlashMode = .On
self.picker.showsCameraControls = false
它足够快,不会因显示和隐藏控件而干扰用户。 工作了!