Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thornpig/d22148323f38095865742f9254d2e9a5 to your computer and use it in GitHub Desktop.
Save thornpig/d22148323f38095865742f9254d2e9a5 to your computer and use it in GitHub Desktop.
Setting contentInset of scrollView makes it jump
The cause of this problem is when the contentInset is set, contentOffset is also set to a value according to the new value of contentInset.
So restore contentOffset to its old value after setting contentInset solves the problem.
It seems the animation block is not needed in my app with iOS 9.0.
- (void)setLoadingScrollViewInsets:(UIScrollView *)scrollView
{
UIEdgeInsets loadingInset = scrollView.contentInset;
loadingInset.top += self.view.frame.size.height;
CGPoint contentOffset = scrollView.contentOffset;
[UIView animateWithDuration:0.2 animations:^
{
scrollView.contentInset = loadingInset;
scrollView.contentOffset = contentOffset;
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment