UIScrollView touchesBegan [英] UIScrollView touchesBegan

查看:124
本文介绍了UIScrollView touchesBegan的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想做的就是在用户触摸UIScrollView时播放声音。
UIScrollViewDelegate具有scrollViewWillBeginDragging:方法,但它只在touchMoved上调用。我想让它在touchBegan上调用。



尝试touchesBegan:withEvent:但它没有任何接触。
任何人都有线索?

解决方案

我认为你必须将UIScrollView子类化才能做到这一点。 / p>

touchesBegan:withEvent:仅发送到UIView的子类。您可以在控制器中实现touchesBegan:withEvent:对吧?如果是这样,它将不起作用...



或者,如果你把UIView的子类(你写的)放在UIScrollView中,你也可以捕获来自那里的touchesBegan事件(但仅当用户触摸该特定子视图时)。
UIScrollView默认将其触摸传递给其子视图(请参阅touchesShouldBegin:withEvent:inContentView:在UIScrollView中)。


So all I wanna do is play a sound when the user touches a UIScrollView. The UIScrollViewDelegate has that scrollViewWillBeginDragging: method but it only gets called on touchMoved. I want it to get called on touchBegan.

Tried touchesBegan:withEvent: but it doesn't receive any touch. Anyone has a clue?

解决方案

I think you will have to subclass UIScrollView to be able to do this.

touchesBegan:withEvent: is only sent to subclasses of UIView. You are problably implementing touchesBegan:withEvent: in your controller, right? If so, it won't work from there...

Alternatively, if you put a subclass of UIView (that you wrote) in your UIScrollView, you can also catch the touchesBegan event from there (but only when the user touches that particular subview). UIScrollView passes on touches to its subviews by default (see touchesShouldBegin:withEvent:inContentView: in UIScrollView).

这篇关于UIScrollView touchesBegan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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