UITableViewCell上的UIPanGestureRecognizer覆盖UITableView的滚动视图手势识别器 [英] UIPanGestureRecognizer on UITableViewCell overrides UITableView's scroll view gesture recognizer
问题描述
我已经将 UITableViewCell
子类化,并且在该类中我应用了平移手势识别器:
I've subclassed UITableViewCell
and in that class I apply a Pan gesture recogniser:
UIPanGestureRecognizer *panning = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePanning:)];
panning.minimumNumberOfTouches = 1;
panning.maximumNumberOfTouches = 1;
[self.contentView addGestureRecognizer:panning];
[panning release];
然后我实现委托协议,应该允许在表格视图中同时进行手势:
I then implement the delegate protocol which is supposed to allow simultaneous gestures in the table's view:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
然后我在 handlePanning
方法只是为了看到它被检测到:
Then I place a log inside the handlePanning
method just to see when it's detected:
- (void)handlePanning:(UIPanGestureRecognizer *)sender {
NSLog(@"PAN");
}
我的问题是,我无法垂直滚动列表表格中的单元格,并且 handlePanning
无论调用哪个方向都会调用。
My problem is that I'm not able to vertically scroll through the list of cells in the tableview and that handlePanning
is called no matter which direction I pan.
我想要的是 handlePanning
仅在只有水平平移而不是垂直时调用。
What I want is for handlePanning
to only be called when there is only horizontal panning and not vertical. Would appreciate some guidance.
推荐答案
您是否尝试过设置 pannings
委托属性?
Have you tried setting pannings
delegate property?
panning.delegate = /* class name with the delegate method in it */;
您还需要将该类符合UIGestureRecognizerDelegate。
You'll also need to conform that class to UIGestureRecognizerDelegate.
这篇关于UITableViewCell上的UIPanGestureRecognizer覆盖UITableView的滚动视图手势识别器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!