1

I have a series of container views inside one scroll view. Currently, the view controller does not scroll vertically. Can a scroll view detect scroll touches through container view controllers?

scrollView

Ivan Lesko
  • 1,274
  • 13
  • 26

2 Answers2

2

I see you aren't using any autolayout constraints, maybe that's the issue.

If you set the contentSize in viewDidLoad: it will get changed when the scrollView hits layoutSubviews.

UIScrollViews need all their contentSize information to match in order to work properly. Autolayout affects that property. You will need constraints that go ALL the way from the top to the bottom and from the left to the right of the scroll view even if IB is not asking for it.

Autolayout manipulation in XCode 6 has some VERY welcome improvements. I recommend updating. I've been using it for the last couple weeks on mavericks and so far so good.

Cheers!

yairsz
  • 438
  • 5
  • 15
0

You could always pass the touches by subclassing the container view. There you can call the parent view controllers respective methods

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.parentViewController touchesBegan:touches withEvent:event];
}
yairsz
  • 438
  • 5
  • 15
  • I'm assuming you did the same for touchesMoved and touchesEnded right? – yairsz Sep 24 '14 at 22:53
  • yep, I did. The tricky part is sending the right data to self.parentViewController's scrollView content offset and making sure it keeps the same animation behavior. – Ivan Lesko Sep 24 '14 at 23:03
  • Also, I see you aren't using any autolayout constraints, maybe that's the issue. Scroll views need to have "0" ambiguity when it comes to contentSize. – yairsz Sep 24 '14 at 23:09
  • I have the scrollview's contentSize set programmatically in view did load. – Ivan Lesko Sep 24 '14 at 23:26
  • Do scrollview's in storyboards not work properly without autolayout constraints? – Ivan Lesko Sep 24 '14 at 23:31
  • Looks like you're right about the autolayout constraints http://stackoverflow.com/questions/20223021/i-am-officially-too-stupid-for-uiscrollview-with-autolayout – Ivan Lesko Sep 25 '14 at 00:18