iOS点按即可聚焦

我使用此代码在iOS自定义相机App中实现了“轻按一下”功能,但无法正常工作。这是代码

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {

let touchPer = touches.anyObject() as UITouch

let screenSize = UIScreen.mainScreen().bounds.size

var focus_x = touchPer.locationInView(self.view).x / screenSize.width

var focus_y = touchPer.locationInView(self.view).y / screenSize.height

if let device = captureDevice {

if(device.lockForConfiguration(nil)) {

device.focusMode = AVCaptureFocusMode.ContinuousAutoFocus

device.focusPointOfInterest = CGPointMake(focus_x, focus_y)

device.exposureMode = AVCaptureExposureMode.ContinuousAutoExposure

device.unlockForConfiguration()

}

}

}

回答:

 device.focusPointOfInterest = focusPoint

device.focusMode = AVCaptureFocusMode.AutoFocus

device.exposurePointOfInterest = focusPoint

device.exposureMode = AVCaptureExposureMode.ContinuousAutoExposure

我不知道为什么这样做,但确实如此。

以上是 iOS点按即可聚焦 的全部内容, 来源链接: utcz.com/qa/401834.html

回到顶部