iosswiftuikit

How can i send the current scrolling position of a scroll view to another, and reconfigure it into the second ? iOS


I have two Views, each one has a scrollView, both of them has the same contents. What i want to do is : When the user hits a button the second view appears and its scroll view "auto-scroll" to the same position the user scrolled on the first one. i tried .getY and it didn't worked.


Solution

  • You can get ScrollView y position after scrolling end by using scrollViewDidScroll function and send to secondView when appear.

    var yPosition : CGFloat = 0
    
    func scrollViewDidScroll(scrollView: UIScrollView!) {
    // new y position of scroll when scroll finished
    
    self.yPosition = scrollView.contentOffset.y
    }
    

    Then,pass this data to secondView and change secondView's scroll.scrollView.contentOffset