【问题标题】:How to pass touch event frome a UIScrollView's subview to it's superview如何将触摸事件从 ScrollView 子视图传递到它的父视图
【发布时间】:2012-03-07 08:38:16
【问题描述】:

我在窗口上有三个视图。一个 UIView 包含 UIScrollView,而 UIScrollView 包含一个 UILabel。所有这些视图都是 320*460。 现在我想处理 UILabel 上的长按事件并将点击事件传递给 UIView。 我重写了标签的 touchesEnded: 以获得新闻发布时间。 如果时间足够短,我使用 [[self nextResponder] touchesBegan:touches withEvent:event] 来传递它。 但是,即使我重写了 UIScrollview 并将 [[self nextResponder] touchesBegan:touches withEvent:event] 添加到它, UIView 也无法接收 touchesBegan 事件。 而且,如果我为 UIScrollView 设置 userInteractionEnabled=NO,UIView 会得到touchedBegan,而UILabel 无法接收它。

如果需要,我如何先在 UILabel 中获取触摸事件并将其传递给 UIView。

谢谢。

【问题讨论】:

  • 感谢您的所有帮助。通过在标签中实现委托方法并在 UIViewController 中实现它,我已经实现了我的目标。

标签: iphone uiscrollview touch-event


【解决方案1】:

我是这样理解你的问题的。

  1. 您需要在 UiLabel 中长按。
  2. 您需要在 UIView 中检测触摸。

UIView 和 UILabel 之间有滚动视图。

  1. 在 UILabel 中添加 UILongpressGesture。 (看here
  2. 从 UIscrollview 传递触摸。

【讨论】:

    【解决方案2】:

    尝试使用 UITapGestureRecognizer 检测 UIScrollView 中的触摸事件

      UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self         action:@selector(singleTapGestureCaptured:)];
      [scrollView addGestureRecognizer:singleTap];    
    

    你会接触到:

      - (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
     { 
       CGPoint touchPoint=[gesture locationInView:scrollView];
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-28
      • 2011-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多