UIScrollView contentInset not working
Check that self.scrollView.contentSize
is set properly. If contentSize.height
is 0 (as will be the case following your steps), then a large inset is required.
Try adding [self.scrollView setContentSize: CGSizeMake(320, 568)];
to the button method and you'll notice that your inset will now behave as expected.
Matt is right, it has to do with self.scrollView.contentSize
. I'm using Auto Layout and the missing link for me was explicitly setting the scrollView's contentSize
property to be the same as my contentView's frame size (contentView is the view inside my scrollView that holds all other views). My contentView is coded to have its size based on the elements I've placed within. They "push out" on the contentView and therefore dynamically drive the contentView's size. It's as a "last step" within viewDidLayoutSubviews
that I link this dynamic size into scrollView.contentSize
. Now things work as expected.
// Auto Layout Solution
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.scrollView.contentSize = self.contentView.frame.size;
}