我想将 iPhoneX 的镜头距离设置为常数。为了检查是否支持,我检查了isLockingFocusWithCustomLensPositionSupported
我的设备的属性,如这里的文档中所述:https ://developer.apple.com/documentation/avfoundation/avcapturedevice/2361529-islockingfocuswithcustomlensposi
该方法总是返回 false,即使设备被锁定以进行配置,这意味着调用该方法总是setFocusModeLocked(lensPosition, completionHandler)
会抛出错误。为什么会这样,如何正确调用setFocusModeLocked()
?
以下是我的方法:
let device = self.deviceInput.device
do {
try device.lockForConfiguration()
if device.isFocusPointOfInterestSupported && device.isFocusModeSupported(focusMode)
{
// this returns true
}
if device.isLockingFocusWithCustomLensPositionSupported
{
//this always returns false
device.setFocusModeLocked(lensPosition: focusDistance, completionHandler: nil)
}
device.unlockForConfiguration()
} catch {
print("Could not lock device for configuration: \(error)")
}
在 iPhoneX、iOS 12 上测试