我正在构建全屏摄像头应用程序,并且允许用户通过点击屏幕来设置兴趣点。但是,当用户移动相机并且视图失去焦点时,我该如何分辨?我想将设备的focusMode
切换为AVCaptureDevice.FocusMode.continuousAutoFocus
,这就是我的代码的样子就像现在一样。
@objc func handleTap(tap: UITapGestureRecognizer) {
let location = tap.location(in: view)
var focusPoint = CGPoint()
focusPoint.x = location.x / view.frame.width
focusPoint.y = location.y / view.frame.height
if let device = currentVideoDevice {
if try! (currentVideoDevice?.lockForConfiguration()) != nil {
if device.isFocusPointOfInterestSupported {
device.focusPointOfInterest = focusPoint
device.focusMode = AVCaptureDevice.FocusMode.autoFocus
}
if device.isExposurePointOfInterestSupported {
device.exposurePointOfInterest = focusPoint
device.exposureMode = AVCaptureDevice.ExposureMode.autoExpose
}
device.unlockForConfiguration()
}
}
}