KK7 KK7 - 4 months ago 20
Swift Question

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

KK7 KK7
Answer

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)

Comments