Question

I'm trying to setup a scroll for a UIView within a UIScrollView.

My view hierarchy is:

UIView (Controller) > UIScrollView > UIView (I'll call this subView from this point on)

I have used the IB to set the layout. I set the top of the subView to be inline with the top of the UIScrollView frame. The subView is as wide as the UIScrollView frame and extends beyond the height of the UIScrollView frame.

In the subView I have UILabels (also set up using the IB). To test the scrolling, I have one label that is just peeking above the bottom border of the UIScrollView frame. When I run the app this label would ideally be able to scroll into view, however, there is no scrolling and the label is just appearing as being cut off where the UIScrollView frame ends.

In the ViewController.m I have the following:

- (void)viewDidLoad
{
self.scrollView.contentSize = self.scrollSubView.frame.size;
}

where scrollSubView is the UIView within the UIScrollView.

What am I missing (doing incorrectly) that is preventing the scroll from working?

Thanks for any assistance offered.

Was it helpful?

Solution

Possible Issue

Autolayout is on, and it won't let scrollview work as required.

Possible Solution

  1. Check for autolayout of storyboard and untick it.

    Autolayout

  2. If you dont want to set it to off, you can follow this short video which is wonderfull to deal scrolling with autolayout. :)

UIScrollView with autolayout on

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top