简体   繁体   English

触摸UIScrollView中不适用于UIViews的事件

[英]Touch events not working on UIViews inside UIScrollView

I have a series of UIViews inside a UIScrollView, and the UIViewControllers for those views are not receiving the touch events. 我在UIScrollView中有一系列UIViews,而那些视图的UIViewControllers没有接收到触摸事件。 If I take the views out of the scroll view then it works. 如果我从滚动视图中取出视图,那么它可以工作。

I have enabled userInteraction on the views but it's still not working! 我已经在视图上启用了userInteraction,但它仍然无法正常工作!

This must be possible and I'd be really grateful if someone could point me in the right direction! 这一定是可能的,如果有人能指出我正确的方向,我真的很感激!

Thanks, 谢谢,

Mike 麦克风

Do the views have their own touch handlers, or are you relying on the viewcontroller to get the touches? 视图是否有自己的触摸处理程序,或者您是否依靠viewcontroller来获取触摸? Depending on how you have set things up, the views may be handling the touches without passing through to the view controller. 根据您的设置方式,视图可能正在处理触摸而不会传递给视图控制器。

我通过覆盖视图控制器的loadView方法,并将视图的实例变量设置为传递触摸的简单UIView子类来克服此问题。

Check what you are returning in scrollview delegate method view for scrollin in scroll view. 在滚动视图中滚动查看滚动视图委托方法视图中返回的内容。

As mahboudz mentioned - check if you have any custom handler for touch event. 正如mahboudz所提到的 - 检查你是否有触摸事件的自定义处理程序。 If not, please have one. 如果没有,请有一个。 Its far more relief to do whatever you want to do with your view. 对你的观点做任何你想做的事情都更加宽慰。 Check out Apples sample app from scrollViewSuite. 从scrollViewSuite查看Apples示例应用程序。 They have tapDetectingImageView delegate. 他们有tapDetectingImageView委托。 I used the same in my app it worked great! 我在我的应用程序中使用了相同的功能,它非常棒 Hope this helps! 希望这可以帮助!

You may find this post useful. 你可能会觉得这篇文章很有用。 It's an example of a pretty clean way of intercepting events. 这是一个非常干净的拦截事件方式的例子。

为您想要接收触摸事件的视图提供触摸处理程序,并且该处理程序将起作用。

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

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