Answers for "swift paged scrollview get current page"

0

swift paged scrollview get current page

// Swift 5

self.scrollView.delegate = self

// Changed the page property when the user scrolls over 50% of the current page.
// Page starts with 0
func scrollViewDidScroll(_ scrollView: UIScrollView) {
  let scrollViewWidth = scrollView.bounds.width
  self.page = Int(round(scrollView.contentOffset.x / scrollViewWidth))
}

var page: Int {
    didSet {
        guard oldValue != self.page else {
          return 
        }
      	// Handle page update
    }
}
Posted by: Guest on January-19-2022

Code answers related to "Swift"

Browse Popular Code Answers by Language