UITableViewCell上的UIPanGestureRecognizer覆盖UITableView的滚动视图手势识别器

我已经分类了UITableViewCell并且在这个类中我应用了一个Pan手势识别器:

 UIPanGestureRecognizer *panning = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePanning:)]; panning.minimumNumberOfTouches = 1; panning.maximumNumberOfTouches = 1; [self.contentView addGestureRecognizer:panning]; [panning release]; 

然后,我实现了这个委托协议,它应该允许在表格视图中同时使用手势:

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } 

然后在handlePanning方法中放置一个日志,以查看它何时被检测到:

 - (void)handlePanning:(UIPanGestureRecognizer *)sender { NSLog(@"PAN"); } 

我的问题是,我无法垂直滚动tableview中的单元格列表,并handlePanning被称为无论我平移哪个方向。

我想要的是handlePanning只在水平平移而不垂直时才被调用。 希望能得到一些指导。

你有没有尝试设置pannings委托属性?

 panning.delegate = /* class name with the delegate method in it */; 

您还需要将该类符合UIGestureRecognizerDelegate。

将平移手势识别器子类化,并使其仅识别水平平移。 关于可用的自定义手势识别器的问题,有一个伟大的WWDCvideo。 其实有两个关于这个问题,检查出来。

使用手势识别器简化触摸事件处理

高级手势识别

添加手势识别器在tableview上。 从那里,你可以得到细胞对象。 从那里你可以处理单元function。 对于每个手势,将会有一个开始,改变,结束的状态。 所以,存储开始位置。

  CGPoint beginLocation = [gesture locationInView:tblView]; // touch begin state. CGPoint endLocation = [gesture locationInView:tblView]; // touch end state. 

使用这一点,你可以得到IndexPath

  NSIndexPath *indexPath = [tblView indexPathForRowAtPoint:beginPoint]; 

从这个索引path,你可以访问单元格。

  UITableViewCell *cell = [tableview cellForRowAtIndexPath : indexPath]; 

使用这个Cell对象,你可以处理它。

你有没有尝试将反弹属性设置为NO?