我有一个覆盖所有UITableView的UIView。UIView使用手势识别器来控制表格显示的内容。我仍然需要垂直的UITableView滚动和行点击。如何将这些信息从手势识别器传递到表中?
发布于 2010-12-17 00:59:58
将你的手势分配给表视图,表会处理它:
UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(handleSwipeFrom:)];
[gesture setDirection:
(UISwipeGestureRecognizerDirectionLeft
|UISwipeGestureRecognizerDirectionRight)];
[tableView addGestureRecognizer:gesture];
[gesture release];
然后在你的手势动作方法中,根据方向采取行动:
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
[self moveLeftColumnButtonPressed:nil];
}
else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) {
[self moveRightColumnButtonPressed:nil];
}
}
在内部处理之后,该表将只传递您所请求的手势。
发布于 2012-01-22 02:17:21
如果您需要知道手机的indexPath:
- (void)handleSwipeFrom:(UIGestureRecognizer *)recognizer {
CGPoint swipeLocation = [recognizer locationInView:self.tableView];
NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:swipeLocation];
UITableViewCell *swipedCell = [self.tableView cellForRowAtIndexPath:swipedIndexPath];
}
这在以前的UIGestureRecognizer and UITableViewCell issue中已经回答过了。
发布于 2012-03-28 15:35:52
我尝试了Rob Bonner的建议,它很有效。谢谢。
但是,在我的例子中,方向识别有一个问题。(recognizer.direction总是引用3)我使用的是IOS5 SDK和xcode4。
这似乎是由“手势setDirection:(左|右)”引起的,我想。(因为预定义的(dir left | dir right)计算结果是3)
因此,如果有人像我一样有问题,想要分别识别向左和向右滑动,那么将两个识别器分配给不同方向的表视图。
如下所示:
UISwipeGestureRecognizer *swipeLeftGesture = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleSwipeLeft:)];
[swipeLeftGesture setDirection: UISwipeGestureRecognizerDirectionLeft];
UISwipeGestureRecognizer *swipeRightGesture = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleSwipeRight:)];
[swipeRightGesture setDirection: UISwipeGestureRecognizerDirectionRight];
[tableView addGestureRecognizer:swipeLeftGesture];
[tableView addGestureRecognizer:swipeRightGesture];
和下面的手势动作:
- (void)handleSwipeLeft:(UISwipeGestureRecognizer *)recognizer {
[self moveLeftColumnButtonPressed:nil];
}
- (void)handleSwipeRight:(UISwipeGestureRecognizer *)recognizer {
[self moveRightColumnButtonPressed:nil];
}
我用ARC功能编码,如果你不使用ARC,添加发布代码。
附言:我的英语不是很好,所以如果有任何句子错误,改正会很高兴:)
https://stackoverflow.com/questions/4454920
复制相似问题