Warm tip: This article is reproduced from serverfault.com, please click

Get UIScrollView to scroll to the top

发布于 2012-02-26 03:32:39

How do I make a UIScrollView scroll to the top?

Questioner
Jack Humphries
Viewed
0
rob mayoff 2014-09-09 05:23:22

UPDATE FOR iOS 7

[self.scrollView setContentOffset:
    CGPointMake(0, -self.scrollView.contentInset.top) animated:YES];

ORIGINAL

[self.scrollView setContentOffset:CGPointZero animated:YES];

or if you want to preserve the horizontal scroll position and just reset the vertical position:

[self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, 0)
    animated:YES];