Search code examples
swiftgesture

Swift reset transitionInView


I have this function:

func moveAxes(recognizer: UIPanGestureRecognizer) {
    switch recognizer.state {
    case .Changed:
        var changePoint = recognizer.translationInView(self)
        axesCenter = CGPoint(x: axesCenter.x + changePoint.x, y: axesCenter.y + changePoint.y)

        print("x: \(changePoint.x) y: \(changePoint.y)")
        changePoint.x = 0.0
        changePoint.y = 0.0
    default:
        break
    }
}

which should move around my axes in UIView. The problem is that

changePoint.x = 0.0
changePoint.y = 0.0

does not reset covered distance and it keeps adding up, so my axes start to accelerate away from the moving point. How can I reset covered distance to avoid this problem?

p.s. axesCenter is initialized as x: frame.midX, y: frame.midY


Solution

  • I've solved my problem by switching this:

    changePoint.x = 0.0
    changePoint.y = 0.0
    

    with this recognizer.setTranslation(CGPoint(x: 0.0, y: 0.0), inView: self)