Reputation: 34798
Why won't basic UIScrollView with a few buttons scroll?
So all I have done is:
But still after all this in the iPhone simulator it won't let me scroll the view?
Upvotes: 2
Views: 1468
Reputation: 1177
No, the correct answer is:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
[self.scrollView setContentSize:CGSizeMake(320, 1700)];
}
The original answer I founded on next link:
UIScrollView won't scroll (Storyboards) -> Find Evana's answer
I waste a lot of time trying implement scroll (and repeatedly). I have even used 2 views (UIScrollView and UIView inside the first)
It is not necessary!
THE KEY IS: viewDidLayoutSubviews
In the storyboard you implement UIScrollView as any other element,
but the key is setContentSize in method viewDidLayoutSubviews
Upvotes: 0
Reputation: 9781
You probably don't want to change your scrollviews frame.size.height
property to 1000.0, but your scrollviews contentSize.height
.
Upvotes: 4
Reputation: 14696
Only one more thing you have to do: set the contentSize
property on your scroll view to an appropriate value:
[scrollView setContentSize:CGSizeMake(
scrollView.bounds.size.width,
CGRectGetMaxY(bottommostSubview.frame)
)];
Where bottommostSubview
is an outlet connected to the subview of the scrollview that’s closest to the bottom. You could also write a method to find this view automatically, or just hard-code a value if you know the size will never change.
The default contentSize
is CGSizeZero
which effectively disables scrolling.
Upvotes: 5