Get UIScrollView to scroll to the top

前端 未结 15 1898
眼角桃花
眼角桃花 2020-12-07 08:41

How do I make a UIScrollView scroll to the top?

15条回答
  •  甜味超标
    2020-12-07 09:34

    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];
    

提交回复
热议问题