我有一个 UIScrollView
带有 subview 和 UITapGestureRecognizer
.
我这样创建识别器:
UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureRecognized:)];
[self addGestureRecognizer:tgr];
UITapGestureRecognizer
的 View 属性指向 ScrollView 本身,即使用户触摸了不同的 View 。我需要知道触摸是否直接在 ScrollView 上下降。
最佳答案
Paul 的建议很好,但如果您不想(或不能)子类化或成为识别器的代表,还有另一种方法。
您可以向手势识别器索取 locationInView:
然后使用您的 ScrollView 的 hitTest:withEvent:
检索该点位于顶部的 View 方法(在 UIView 上定义)。就像是:
CGPoint location = [recognizer locationInView:scrollView];
UIView *touchedView = [scrollView hitTest:location withEvent:nil];
关于iphone - 如何确定 UITapGestureRecognizer 触摸了哪个 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18455053/