我有一个UIView覆盖了所有的UITableView。 UIView使用手势识别器来控制表格显示的内容。 我仍然需要垂直UITableView滚动和行水龙头。 如何从手势识别器将这些传递到桌子上?手势识别器和TableView
回答
将您的姿态向表视图,该表将照顾它:
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];
}
}
该表将只有通过你在内部处理之后所要求的手势。
这是很好的答案。但是,你能告诉我如何知道handleSwipeFrom方法中的tableview indexPath吗? – dinesh 2012-01-20 10:14:48
这不起作用 - UISwipeGestureRecognizer上的direction属性指示可以识别哪些方向(在本例中是左和右)而不是WAS滑动的方向。您需要分离手势识别器 – 2013-09-02 10:22:12
是的,recognitionizer.direction将始终为3并且永不匹配。这可以说是一个错误:http://stackoverflow.com/questions/3319209/setting-direction-for-uiswipegesturerecognizer – Symmetric 2013-09-29 03:33:16
如果你需要知道你的电池的indexPath:
- (void)handleSwipeFrom:(UIGestureRecognizer *)recognizer {
CGPoint swipeLocation = [recognizer locationInView:self.tableView];
NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:swipeLocation];
UITableViewCell *swipedCell = [self.tableView cellForRowAtIndexPath:swipedIndexPath];
}
我试过Rob Bonner的建议,它的效果很好。谢谢。
但是,在我的情况下,方向识别存在问题。 (recognitionizer.direction总是指3)我使用IOS5 SDK和Xcode 4.
这似乎是由“[gesture setDirection:(left | right)]”引起的。 (因为预定义的(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功能再编码,增加发行代码。
PS:我的英语不太好,所以如果有任何句子错误,修正会很高兴:)
- 1. Swift/UIView与TableView和手势识别器问题
- 2. 添加手势识别器
- 3. cocos2d-iOS - 手势识别器
- 4. 点击手势识别器
- 5. 捏捏手势识别器
- 6. SpriteKit手势识别器
- 7. Kinect手势识别
- 8. 3D手势识别
- 9. 如何从一个手势识别器到另一个手势识别器
- 10. 我可以发现tableviewcell中tableview手势识别器的状态
- 11. TableView手势识别器影响滑动删除行
- 12. UItextview与手指手势识别器
- 13. 手指跟踪和手势识别
- 14. 叩击手势手势识别器无法正常工作
- 15. Windows手势识别器内置的手势指标是什么?
- 16. 图片+捏手势识别器
- 17. 整个UIView的手势识别器
- 18. iPad手势识别器 - 延迟响应
- 19. UIImageView上重叠的手势识别器
- 20. ScrollView - 手势识别器 - 垂直滑动
- 21. UIButton检测按住“手势识别器”?
- 22. 检查特定的手势识别器
- 23. 禁用手势识别器iOS
- 24. 改变手势识别器的索引
- 25. 添加滑动手势识别器DetailViewContoller
- 26. Xamarin Forms - Tap手势识别器等效
- 27. 所有事件的手势识别器
- 28. 没有GLKViewController的GLKView手势识别器
- 29. 手势识别JavaScript库
- 30. C#HMM手势识别Kinect
我相信“[tablView手势]”应为“[yourTableView addGestureRecognizer:手势]” – 2011-06-23 19:17:15