Swift 3
Установить режим фокусировки на вашем AVCaptureDevice
экземпляре:
do {
try videoCaptureDevice.lockForConfiguration()
videoCaptureDevice.focusMode = .continuousAutoFocus
videoCaptureDevice.unlockForConfiguration()
} catch {}
Добавить наблюдателя:
videoCaptureDevice.addObserver(self, forKeyPath: "adjustingFocus", options: [.new], context: nil)
Переопределить observeValue
:
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
guard let key = keyPath, let changes = change else {
return
}
if key == "adjustingFocus" {
let newValue = changes[.newKey]
print("adjustingFocus \(newValue)")
}
}