为什么UIPanGestureRecognizer有奇怪的移动距离DELAY?

时间:2016-12-19 18:45:38

标签: ios uigesturerecognizer uipangesturerecognizer

我有一个不同的简单案例:

- (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];
}
  

解释

非常简单。只需添加UITapGestureRecognizer和UIPanGestureRecognizer,每个gestureRecognizer都会绑定一个动作。

但是,奇怪的是,如果你慢慢地移动你的手指(非常非常慢),你可以看到红色的testView根本不移动。它只是开始移动一次手指移动的距离大于 5px 。那就是谜!那么,如何使testView响应手指立即移动任何延迟。

我做了一些工作。其中一种方法是子类UIPanGesture名为 MMUIPanGestureRecognizer ,它实际上解决了延迟问题,并且testView响应手指立即移动。但是,另一个奇怪的事情即将来临。 它会阻止所有手势,除了MMUIPanGestureRecognizer 即可。圣洁的xxx!

我将我的简单测试项目推送到Github,您可以查看Here

感谢您的帮助!

0 个答案:

没有答案