WHY UIPanGestureRecognizer has weird move distance DELAY?

814 views Asked by At

I have a vary simple case:

- (void)viewDidLoad {
  [super viewDidLoad];

  UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
  testView.backgroundColor = [UIColor redColor];
  testView.center = self.view.center;
  [self.view addSubview:testView];

  UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
  [testView addGestureRecognizer:tapGR];

  UIPanGestureRecognizer *panGes = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
  [testView addGestureRecognizer:panGes];
}

- (void)handlePan:(MMUIPanGestureRecognizer *)panGes {
  panGes.view.center = [panGes locationInView:self.view];
}

- (void)handleTapGesture:(UITapGestureRecognizer *)tapGR {
  tapGR.view.backgroundColor = [UIColor colorWithRed:arc4random() % 2 green:arc4random() % 2 blue:arc4random() % 2 alpha:1.0];
}

Explain

It's very simple.Just add a UITapGestureRecognizer and a UIPanGestureRecognizer,and each gestureRecognizer binds a action.

But, the weird thing is that,if you move your finger slowly(very very slowly), you can see the red testView don't move at all.It just begin to move once the distance you finger moved is more than about 5px. That's puzzle! SO, how to make the testView responses finger moving instantly with any delay.

I made some work. One of ways is subclass UIPanGesture named MMUIPanGestureRecognizer, it actually solve the delay issue and the testView responses finger moving instantly.But,another weird thing coming.It prevent all of gestures except the MMUIPanGestureRecognizer. Holy xxx!

I push my simple test project to Github,you can check out Here.

Thanks for helping indeed!

0

There are 0 answers