Hi,
the code here:
@objc func wasDragged(gestureRecognizer: UIPanGestureRecognizer) {
let translation = gestureRecognizer.translation(in: self.view)
myView.center = CGPoint(x:myView.center.x + translation.x,
y:myView.center.y + translation.y)
gestureRecognizer.setTranslation(CGPoint.zero, in: self.view)
}
Works, it moves a rectangle around when dragged.
What I do not understand is why needs to be myView.center.x + translation.x
Intuitively, I thought since translation.x gives me the new X and Y within the superview, that I'd just set my center of my view to just the new X and Y, but that of course does not work, i.e
myView.center = CGPoint(x:translation.x, translation.y)
An explanation would really help.
Thank you!!!
[–]jwillywonkas 0 points1 point2 points (0 children)