KK7 KK7 - 1 year ago 134
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

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?

is initialized as
x: frame.midX
y: frame.midY

Answer Source

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)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download