0

Currently I'm making a custom view with a scrollView inside it. I've got following views hierarchy now:

    -> UIView (self)
    |--> UIScrollView
      |---> UIView (itemsContainer)
         |---> UIView (testView)
         |---> UIView (testView)
         |---> UIView (testView)

and so on (I've got about hundred testViews here). Note that "testView" is just an example (instead of it, it may be any view you like)

TestView is created from xib and has a UIButton. ScrollView consumes all touches and button's touchUpInside event didn't fire. How can I forward touches from ScrollView to it's subviews???

Note that if I remove ScrollView from hierarchy and place itemsContainer without it, all will work fine. Also: I need to forward touches not only to UIButtons. It can be 5 buttons and 2 switches on testView in example. How can I solve this problem?

  • https://stackoverflow.com/questions/3132147/uibutton-inside-uiscrollview-doesnt-fire-on-tap ? – Larme Aug 11 '17 at 08:35
  • just a side note on your question: in your situation using a UIScrollView is a bad practice use UITableView instead – zombie Aug 11 '17 at 08:44
  • Possible duplicate of [ScrollView gesture recognizer eating all touch events](https://stackoverflow.com/questions/16882737/scrollview-gesture-recognizer-eating-all-touch-events) – Rishabh Aug 11 '17 at 08:46
  • I can't use UITableView 'cause I'm making a custom collection and my items placed not side-by-side. Also, link above isn't work for me, 'cause my UIButtons not laying inside a scrollView directly. All interactions are enabled of course – JustSay Ozz Aug 11 '17 at 08:47

2 Answers2

0

Try using:

[scrollView setExclusiveTouch:YES];
[scrollView setUserInteractionEnabled:YES];
[scrollView setCanCancelContentTouches:YES]; 
[scrollView setDelaysContentTouches:YES];
Alan
  • 1,132
  • 7
  • 15
  • It doesn't help – JustSay Ozz Aug 11 '17 at 08:54
  • How about using the solution from this. https://stackoverflow.com/questions/4941570/iphone-click-view-behind-transparent-uiscrollview?rq=1 If it doesn't work you can try adding a tapGestureRecognizer on the scrollView and handling the selector method similarly to this question: https://stackoverflow.com/questions/27193136/how-to-send-the-touch-events-of-uiscrollview-to-the-view-behind-it?rq=1 – Alan Aug 11 '17 at 09:00
0

In my case the itemContainer size, autoresized, was finally equal to zero, cause some wrongs constraint. So the layout was apparently correct because clipSubView property was set to false, but when I've enable this property I discover that the only view really visible and touchable was the scrollview.

christian mini
  • 1,662
  • 20
  • 39