代码之家  ›  专栏  ›  技术社区  ›  indragie

uigestureRecognizer阻塞表视图滚动

  •  7
  • indragie  · 技术社区  · 15 年前

    我正在使用一个自定义 UIGestureRecognizer 子类跟踪我的 InfoView 班级。这个 信息视野 类是自定义的子视图 UITableViewCell 子类称为 InfoCell .

    我已将手势识别器添加到根视图(屏幕上其他所有内容的父视图),因为我的自定义手势识别器的目的是允许拖动 信息枪 表之间的视图)。现在,除了一件事,一切都按它应该的方式工作。我在我的 最大识别器 子类,用于检测 信息视野 观点:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        UIView *touchView = [[touches anyObject] view];
        if ([touchView isKindOfClass:[InfoView class]]) {
            // Do stuff
        }
    

    这里的问题在于 信息视野 对象被截获,因此不会转发到 UITableView 其中包含 信息枪 ,它是 信息视野 . 这意味着通过拖动 信息视野 视图,这是一个问题,因为 信息视野 覆盖整个 信息枪 .

    我是否可以将触摸向前移到表视图上,以便它可以滚动?我已经尝试了很多事情:

    [super touchesBegan:touches withEvent:event];

    [touchView.superview.superview touchesBegan:touches withEvent:event]; ( touchView.superview.superview 获取对其父级的引用 UITababVIEW )

    但到目前为止,还没有任何进展。此外, cancelsTouchesInView 我的财产 最大识别器 设置为 NO 这样就不会干扰触摸。

    感谢您的帮助。谢谢!

    4 回复  |  直到 12 年前
        1
  •  25
  •   Mark Adams    14 年前

    查看uigestureRecognizerDelegate方法: - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

    如果返回“是”,将阻止手势识别器踩踏uiscrollview用于检测滚动的对象。

        2
  •  9
  •   Felix    15 年前

    uigestureRecognizer有一个属性“cancelstouchesinView”,默认设置为“是”。这意味着当识别出手势时,uiview中的触摸将被取消。尝试将其设置为“否”以允许uiscrollview接收进一步的触摸事件。

        3
  •  3
  •   indragie    15 年前

    我有一条线在我的 touchesBegan 设置 state 手势识别器的属性 UIGestureRecognizerStateBegan . 删除此行似乎可以解决问题。

        4
  •  3
  •   user2182192    12 年前

    您可以尝试添加此通知

    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
        if ([gestureRecognizer class] == [UIPanGestureRecognizer class]) {
            UIPanGestureRecognizer *panGestureRec = (UIPanGestureRecognizer *)gestureRecognizer;
            CGPoint point = [panGestureRec velocityInView:self];
            if (fabsf(point.x) > fabsf(point.y) ) {
                return YES;
            }
        }
        return NO;
    }
    
    推荐文章