将触摸从 UIScrollView 传递到 superview (UIButton)

Pass touch from UIScrollView to superview (UIButton)(将触摸从 UIScrollView 传递到 superview (UIButton))
本文介绍了将触摸从 UIScrollView 传递到 superview (UIButton)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

可能是重复的,但我找不到我今晚搜索问题的确切答案...

Possibly a duplicate, but I couldn't find an exact answer to my problem searching SO tonight...

我有一个 UIButton,其中包含一个 UIScrollView,所以该按钮是超级视图.

I have a UIButton which contains a UIScrollView, so the button is the superview.

我想要做的就是将单击事件从 UIScrollView 子视图传递到 UIButton 超级视图,并拥有 UIButton 句柄就像用户直接点击按钮一样.

All I want to do is pass a single-tap event from the UIScrollView subview to the UIButton superview, and have the UIButton handle it as it would if the user tapped the button directly.

将滚动视图的 userInteractionEnabled 属性设置为 NO 对我不起作用,因为用户可以滚动内容.这样做会破坏滚动视图的目的.

Setting the scroll view's userInteractionEnabled property to NO won't work for me because there is content the user can scroll. Doing so would defeat the purpose of the scroll view.

这可能吗?谢谢!

推荐答案

就像火心鸟说的那样,你的观点肯定不常见.

Like huoxinbird said, it's definitely not common to lay your views like that.

如果您对此非常坚持,您可以使用 UITapGestureRecognizer 并让它调用按钮的目标和选择器.

In the case where you are solidly adamant about this, you could use UITapGestureRecognizer and have it call the button's target and selector.

如果您想包括按钮突出显示等,那么您可能必须继承 UITapGestureRecognizer 并将 touchesEnded 转发给按钮.

If you wanted to include the button highlight and such, then you may have to subclass UITapGestureRecognizer and forward the touchesEnded to the button.

这篇关于将触摸从 UIScrollView 传递到 superview (UIButton)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的边缘工作)
ImageView Scaling when scrolling down(向下滚动时 ImageView 缩放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的边界自动更改,带有内容插图)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
Handling scroll views with (custom, interactive) view controller presentation and dismissal(使用(自定义、交互式)视图控制器呈现和解除处理滚动视图)