Having a little problem understanding how to implement a faster drag and drop speed for the code I use below (written by @PaulSoltz) that allows you to drag and drop an object around the screen. I understand that you must use the velocityInView method from UIPanGestureRecognizer , and I understand that it returns the velocity vector x and the velocity vector y. If speed = distance in time, then, for example, velocityx = (x2 - x1) / time , and I'm not sure how to use this formula to get what I need. Basically, I just want to be able to adjust the speed of my movement to make it a little faster. I may be thinking, but if anyone can help me figure this out, it will be appreciated. Thanks.
- (void)handlePanGesture:(UIPanGestureRecognizer *)gestureRecognizer { UIView *myView = [gestureRecognizer view]; CGPoint translate = [gestureRecognizer translationInView:[myView superview]]; if ([gestureRecognizer state] == UIGestureRecognizerStateChanged || [gestureRecognizer state] == UIGestureRecognizerStateChanged) { [myView setCenter:CGPointMake(myView.center.x + translate.x, myView.center.y + translate.y)]; [gestureRecognizer setTranslation:CGPointZero inView:[myView superview]]; } }
source share