Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView won't scroll (Storyboards)

I'm new to Storyboards; I've done some Interface Builder before and lots of manual UI positioning. I've searched this issue, tried the solutions found in the other relevant posts, to no avail.

I have a view controller with a UIScrollView added in Storyboards. The ScrollView outlet has been connected, the property synthesized. Scrolling Enabled is checked. Bounces is checked. Even then there was no indication that any scrolling would take place. When I checked Bounces Vertically, I could at least see the scrollable content, but it bounces back after I release. The frame size I found set at 320 and 521. I experimented with different heights but nothing helped. (What ought to be the size set in Storyboards that will accommodate the older and newer phone sizes?).

In viewDidLoad, I added

    [scrollView setContentSize:CGSizeMake(320, 1000)];

A log statement afterwards confirms that this value has been accepted. But it didn't help either.

Someone in one post suggested adding:

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    [self.scrollView setContentSize:CGSizeMake(320, 808)];
}

This had the effect of crashing the program when the controller loaded.

Any help would be greatly appreciated!

Thanks.

like image 439
Casey Perkins Avatar asked Oct 18 '13 20:10

Casey Perkins


2 Answers

Two things turned out to be necessary:

1) Set height of scrollview to 480.

2) Add constraint to the bottommost field in the scrollview. The constraint was Pin >> Bottom Space to Superview.

like image 196
Casey Perkins Avatar answered Sep 25 '22 15:09

Casey Perkins


Just add the following method:

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    [self.scrollView setContentSize:CGSizeMake(320, 1700)];
}

This is working perfectly for me.

like image 26
Evana Avatar answered Sep 24 '22 15:09

Evana