设置照相机焦点在与迅速的轻拍点 [英] Set Camera Focus On Tap Point With Swift

查看:509
本文介绍了设置照相机焦点在与迅速的轻拍点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在swift中使用相机的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)
{

self._currentDevice.unlockForConfiguration()
}

_currentDevice.setFocusModeLockedWithLensPosition(focusY)
{
time in
self._currentDevice.unlockForConfiguration ()
}
}

但它似乎无效。

解决方案

结束它的非常简单的:

  _currentDevice.lockForConfiguration(nil)
_currentDevice.focusPointOfInterest = tap.locationInView(self)
_currentDevice .unlockForConfiguration()


The API for using the camera in swift seems a but different and I am having a hard time focusing the camera on a point. When the user taps the screen I want the camera to focus on that point

This is my code:

 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()
        }
    }

But it doesnt seem to work.

Any suggestions are more than welcome!

解决方案

Turns out its very simple:

_currentDevice.lockForConfiguration(nil)
_currentDevice.focusPointOfInterest = tap.locationInView(self)
_currentDevice.unlockForConfiguration()

这篇关于设置照相机焦点在与迅速的轻拍点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆