Touch events not working on UIViews inside UIScrol

2019-04-01 02:15发布

问题:

I have a series of UIViews inside a UIScrollView, and the UIViewControllers for those views are not receiving the touch events. 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!

This must be possible and I'd be really grateful if someone could point me in the right direction!

Thanks,

Mike

回答1:

Do the views have their own touch handlers, or are you relying on the viewcontroller to get the touches? Depending on how you have set things up, the views may be handling the touches without passing through to the view controller.



回答2:

I have overcome this issue by overriding the loadView method of the view controller, and setting the view's instance variable to a simple UIView subclass which passes on the touches.



回答3:

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. 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. They have tapDetectingImageView delegate. I used the same in my app it worked great! Hope this helps!



回答4:

You may find this post useful. It's an example of a pretty clean way of intercepting events.



回答5:

Have touch handlers for view for which you want to receive touch events and that will work.