自定义 swift 相机圈触摸响应

Custom swift camera circle touch response

我正在尝试向我的自定义相机添加一个圆圈 view.I 无法将其置于我的 "touch point" 中心,因为当我触摸屏幕时它会将我的圆圈添加到左上角,但是当我在第二行代码中用一些 CGPoint(//Some constrains) 替换 arcCenter 旁边的 "centerPoint" 时,它会将我的点添加到正确的 CGPoint.

到目前为止,这是我的代码:

func pointInCamera(centerPoint:CGPoint){


        let circlePath = UIBezierPath(arcCenter: centerPoint, radius: CGFloat(30), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)//This "centerPoint" is the problem I guess             
        let shapeLayer = CAShapeLayer()
        shapeLayer.path = circlePath.CGPath

        shapeLayer.fillColor = UIColor(red: 240/255, green: 240/255, blue: 240/255, alpha: 0.3).CGColor
        shapeLayer.strokeColor = UIColor(red: 0, green: 191/255, blue: 1, alpha: 0.9).CGColor
        shapeLayer.lineWidth = 2.0

        view.layer.addSublayer(shapeLayer)

    }

    //Focus camera

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        let screenSize = cameraView.bounds.size
        if let touchPoint = touches.first {
            let x = touchPoint.locationInView(cameraView).y / screenSize.height
            let y = 1.0 - touchPoint.locationInView(cameraView).x / screenSize.width
            let focusPoint = CGPoint(x: x, y: y)

            let backCamera = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)

            if let device = backCamera {
                do {
                    try device.lockForConfiguration()
                    device.focusPointOfInterest = focusPoint

                    pointInCamera(focusPoint)
                    device.focusMode = .AutoFocus
                    device.exposurePointOfInterest = focusPoint
                    device.exposureMode = AVCaptureExposureMode.ContinuousAutoExposure
                    device.unlockForConfiguration()


                }
                catch {
                    // just ignore
                }
            }
        }
    }

我创建了这个函数并将其添加到我的 touchesBegan 函数中:

func pointInCamera(centerPoint:CGPoint){

        let circlePath = UIBezierPath(arcCenter: centerPoint, radius: CGFloat(30), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)

        let shapeLayer = CAShapeLayer()
        shapeLayer.path = circlePath.CGPath

        shapeLayer.fillColor = UIColor(red: 240/255, green: 240/255, blue: 240/255, alpha: 0.3).CGColor
        shapeLayer.strokeColor = UIColor(red: 0, green: 191/255, blue: 1, alpha: 0.9).CGColor
        shapeLayer.lineWidth = 2.0

        view.layer.addSublayer(shapeLayer)

        delay(0.5) { 
            shapeLayer.removeFromSuperlayer()
        }

    }