【问题标题】:UITableView swipe gesture requires near perfect accuracyUITableView 滑动手势需要近乎完美的准确度
【发布时间】: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


【解决方案1】:

正如 Twitter 上的 Kolin Krewinkel 所指出的,实现这两个委托方法就可以了:

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

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

【讨论】:

  • 这最初对我有用,但是在为我的 tableview 制作子类之后,我还必须在我的所有 tableview 预先存在的识别器上调用 requireGestureRecognizerToFail 。否则垂直和水平识别器会相互干扰。希望这可以节省一些时间!
【解决方案2】:

我在 UITableView 上使用 ECSlidingViewController 和滑动删除时遇到了类似的问题(在我的案例中,顶视图控制器向左滑动以显示菜单)。

我通过向我的ECSlidingViewController 的默认panGesture 属性添加一个委托来解决这个问题,这样只有在屏幕的最右侧边缘开始滑动时才会拉入菜单:

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
  if ([gestureRecognizer locationInView:gestureRecognizer.view].x > ([UIScreen mainScreen].bounds.size.width - 60.0))
  {
    return YES;
  }
return NO;
}

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    相关资源
    最近更新 更多