简体   繁体   English

将触摸从UIScrollView传递到下面的UIButton

[英]Pass touch from UIScrollView to UIButton underneath

Here's my setup: I have one main view, which has several UIButtons inside, as well as a UIScrollView . 这是我的设置:我有一个主视图,其中有几个UIButtons以及一个UIScrollView The UIScrollView has two UIImageView s within it. UIScrollView有两个UIImageView The UIScrollView in the layer order is on top of the UIButtons . 层顺序的UIScrollViewUIButtons顶部。

What I would like to happen is that the UIScrollView would pass touches to the UIButtons underneath it if the touches within the UIScrollView are not on either UIImageView . 我想发生的是,如果UIScrollView中的触摸不在两个UIImageView上,则UIScrollView会将触摸传递到其下方的UIButtons

Any idea on how to set this up? 关于如何进行设置的任何想法?

Thanks for any guidance. 感谢您的指导。

You could override the hit testing mechanisms of the scroll view to accomplish exactly what you are asking, but honestly that is more work than you need to do any may well give unexpected results. 您可以覆盖滚动视图的点击测试机制以完全完成您所要求的操作,但是说实话,这比您要做的任何工作都要多,这很可能会带来意想不到的结果。

A better approach would be to add a tap gesture recognizer to the scroll view and have the handler perform the same action as the corresponding button. 更好的方法是将滚动手势识别器添加到滚动视图,并使处理程序执行与相应按钮相同的操作。

EDIT: 编辑:

Based on a better understanding of what you are trying to do, you should make your buttons subviews of a custom UIScrollView and override -layoutSubviews to dynamically reposition them so that they stay in a fixed location. 基于对要执行的操作的更好理解,您应该使按钮成为自定义UIScrollView的子视图,并覆盖-layoutSubviews以动态地重新放置它们,以便将它们保持在固定位置。 If you can't/don't want to subclass UIScrollView, you can try an alternate approach that I outlined in response to a similar question . 如果您不想/不想继承UIScrollView,可以尝试使用我针对类似问题概述的替代方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM