Swift 3
Set chế độ tập trung vào AVCaptureDevice
dụ của bạn:
do {
try videoCaptureDevice.lockForConfiguration()
videoCaptureDevice.focusMode = .continuousAutoFocus
videoCaptureDevice.unlockForConfiguration()
} catch {}
Thêm quan sát viên:
videoCaptureDevice.addObserver(self, forKeyPath: "adjustingFocus", options: [.new], context: nil)
Override 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)")
}
}
này không cho bạn biết liệu tự động lấy nét thất bại, mặc dù. Ngay cả khi AdjustFocus trở thành sai, nó không nhất thiết có nghĩa là máy ảnh đang được lấy nét. –
Phương pháp này cũng không thành công trên các thiết bị lớp 6/6Plus/6S/6S Plus của iPhone, vì có chế độ lấy nét tự động khác nhau khi AdjustFocus không chính xác. –
Giá trị của khóa ISO là gì? – Nil