快速使用相机的API似乎有些不同,但我很难将相机聚焦在某个点上。当用户点击屏幕时,我希望相机将焦点对准该点
这是我的代码:
func focusCamera(point:CGPoint) { var screenRect:CGRect = bounds var focusX = Float(point.x/screenRect.width) var focusY = Float(point.y/screenRect.height) _currentDevice.lockForConfiguration(nil) _currentDevice.setFocusModeLockedWithLensPosition(focusX) { time in self._currentDevice.unlockForConfiguration() } _currentDevice.setFocusModeLockedWithLensPosition(focusY) { time in self._currentDevice.unlockForConfiguration() } }
但这似乎不起作用。
任何建议都值得欢迎!
事实证明,它非常简单:
_currentDevice.lockForConfiguration(nil) _currentDevice.focusPointOfInterest = tap.locationInView(self) _currentDevice.unlockForConfiguration()