Get UIScrollView to scroll to the top

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

How do I make a UIScrollView scroll to the top?

15条回答
  •  孤街浪徒
    2020-12-07 09:40

    Answer for Swift 2.0/3.0/4.0 and iOS 7+:

    let desiredOffset = CGPoint(x: 0, y: -self.scrollView.contentInset.top)
    self.scrollView.setContentOffset(desiredOffset, animated: true)
    

提交回复
热议问题