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

ios-获取UIScrollView滚动到顶部

(ios - Get UIScrollView to scroll to the top)

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

如何使UIScrollView滚动到顶部?

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

iOS 7更新

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

原来的

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

或者,如果你想保留水平滚动位置并仅重置垂直位置,请执行以下操作:

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