Good day. Just started to learn gestures in iOS, I run the tutorial http://www.appcoda.com/ios-gesture-recognizers/ . I got to Pan Gesture Recognizer, and there was a problem: after assigning vertical and horizontal speed values ​​to labels, the gesture “breaks”. UIVIew no longer moves smoothly with the mouse cursor, but jumps to the place where the mouse cursor stopped. Label values ​​are updated without problems. Below is the code that implements the movement of the test view:
PanViewController.h @interface PanViewController : UIViewController @property (weak, nonatomic) IBOutlet UIView *testView; @property (weak, nonatomic) IBOutlet UILabel *horizontalVelocityLabel; @property (weak, nonatomic) IBOutlet UILabel *verticalVelocityLabel; @end PanViewController.m @interface PanViewController () - (void)moveViewWithGestureRecognizer:(UIPanGestureRecognizer *)panGestureRecognizer; @end @implementation PanViewController - (void)viewDidLoad { [super viewDidLoad]; UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveViewWithGestureRecognizer:)]; [self.testView addGestureRecognizer:panGestureRecognizer]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)moveViewWithGestureRecognizer:(UIPanGestureRecognizer *)panGestureRecognizer { CGPoint touchLocation = [panGestureRecognizer locationInView:self.view]; self.testView.center = touchLocation; After adding the following lines to the last method, there is a problem with incorrect execution of the drag gesture, although no errors occur:
CGPoint velocity = [panGestureRecognizer velocityInView:self.view]; self.horizontalVelocityLabel.text = [NSString stringWithFormat:@"Horizontal Velocity: %.2f points/sec", velocity.x]; self.verticalVelocityLabel.text = [NSString stringWithFormat:@"Vertical Velocity: %.2f points/sec", velocity.y]; } How do I fix this "breakdown"? I really want to understand what I am doing wrong, and not to continue further studies without understanding the problem. Thank you in advance.