How to reset my UIScrollView's position after returning from a modal transition?

前端 未结 6 849
-上瘾入骨i
-上瘾入骨i 2021-02-07 12:46

I have a simple view containing a long view with many buttons, with the whole thing being in a UIScrollView. The scroller works well, and I can s

6条回答
  •  长发绾君心
    2021-02-07 13:03

    First, thanks for the approved answer above. Someone mentioned that it was no longer applicable but I have a scrolling view inside of table view cell and it needs to be reset when the cell is reused.

    Here is the solution in Swift.

    @IBOutlet var scrollView: UIScrollView!
    
    // many lines of code later inside a function of some sort...
    
    scrollView.setContentOffset(CGPointMake(0.0, 0.0), animated: false)
    

提交回复
热议问题