UIButton传递到UIScrollView的直击式滚动手势 [英] UIButton pass-through tap-and-scroll gesture to UIScrollView
问题描述
我有一个水平分页的 UIScrollView
和一个 UIButton
部分覆盖了滚动视图。
I have a horizontal paginated UIScrollView
with a UIButton
partially covering the scroll view.
就像这样:
UIView
|
|- UIScrollView
|
|- UIButton
我要制作 UIButton
不会在 tap-scroll-and-relase-above-the-button 上触发(我希望 UIScrollView
滚动)。我希望按钮仅响应轻按并释放,而不会移动。
I want to make the UIButton
to not trigger on tap-scroll-and-relase-above-the-button (I want the UIScrollView
to scroll instead). I want the button to only respond to tap-and-release-without-moving.
可以轻松,快速地完成此操作吗?还是应该将 UIButton
子类化并覆盖 -touchesBegan:
等,以将触摸手动传递给 scrollView
在适当的时候?
Can this easy and quickly done? Or should I subclass the UIButton
and override -touchesBegan:
, etc., to manually pass the touches to the scrollView
when appropriate?
推荐答案
经过一些额外的研究,我找到了一个合理的解决方案。这里的问题是 UIScrollView
和 UIButton
不在同一响应者链层次结构中:两者的下一个响应者是父 UIView
,因此默认情况下它们不会相互发送事件。
After some additional research I found a reasonable solution. The problem here is that UIScrollView
and UIButton
are not in the same responder-chain hierarchy: the next responder for both is the parent UIView
, so they don't send events to each other by default.
解决方案是子类 UIButton
并实现
- (UIResponder *)nextResponder
方法,以便它返回 UIScrollView
。
另一种解决方案是使 UIButton
成为<$的子代c $ c> UIScrollView 。但是,如果无论单元格滚动如何都希望将按钮保持在固定位置,那将无法正常工作。
An alternate solution is to make the UIButton
a child of the UIScrollView
. However, that doesn't work great if you want to keep the button at a fixed position regardless of cell scrolling.
令人烦恼的是,没有更简单的方法可以做到这一点。 :-)
It's somewhat annoying that there's no simpler way of doing this. :-)
这篇关于UIButton传递到UIScrollView的直击式滚动手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!