从UIScrollView传递触摸到superview(UIButton) [英] Pass touch from UIScrollView to superview (UIButton)

查看:194
本文介绍了从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 superview,并且 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 属性设置为否将不适用于我,因为有内容,用户可以滚动。这样做会失败滚动视图的目的。

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.

这是否可能?感谢!

推荐答案

像huoxinbird说的,这绝对不常见,像这样放置你的意见。

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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆