【发布时间】:2013-03-31 04:42:43
【问题描述】:
我正在为使用自定义 UITableViewCell 子类的 UITableView 处理自定义滑动事件。我在标题中包含了UIGestureRecognizerDelegate,并在viewDidLoad:中包含了这个
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeft.numberOfTouchesRequired = 1;
[self.tableView addGestureRecognizer:swipeLeft];
我的 swipeLeft 方法如下所示:
-(void)didSwipe:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateEnded)
{
CGPoint swipeLocation = [recognizer locationInView:self.tableView];
NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:swipeLocation];
NSDictionary *clip = [self.clips objectAtIndex:swipedIndexPath.row];
NSLog(@"Swiped!");
}
}
这是排序的工作,但滑动必须非常精确。几乎不可能精确。
我几乎通过使用 UIPanGestureRecognizer 来让它工作,但不幸的是,它与使用全局平移手势识别器的全局侧抽屉组件(感兴趣的人可以使用 ECSlidingViewController)配合得不好。
有没有办法解决这个问题?任何帮助将不胜感激,因为我一直在谷歌搜索和浏览 SO 几个小时以寻找解决方案。
【问题讨论】:
-
那么是用户在特定单元格上滑动,还是在 tableview 本身上滑动?
-
@MishieMoo 一个单元格,但我读到最好在整个 tableview 上实现 GR 并使用 CG 点来获取被刷过的单元格。
-
作为旁注,我确实尝试将它应用到一个单元格,但我遇到了完全相同的问题。
-
那么究竟是什么问题呢?是不是找错了单元格?还是您无法获得滑动的好点?
-
@MishieMoo 这是关于滑动需要太精确的滑动。滑动几乎必须是完全水平的,这几乎是不可能自然做到的。
标签: ios cocoa tableview uigesturerecognizer swipe