Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
  2.  
  3. // Page width used for estimating and calculating paging.
  4. let pageWidth = (self.frame.width) - interIntemMargin
  5.  
  6. // Make an estimation of the current page position.
  7. let approximatePage = scrollView.contentOffset.x/pageWidth
  8.  
  9. // Determine the current page based on velocity.
  10. let currentPage = (velocity.x < 0.0) ? floor(approximatePage) : ceil(approximatePage)
  11.  
  12. // Create custom flickVelocity.
  13. let flickVelocity = velocity.x * 0.3
  14.  
  15. // Check how many pages the user flicked, if <= 1 then flickedPages should return 0.
  16. let flickedPages = (abs(round(flickVelocity)) <= 1) ? 0 : round(flickVelocity)
  17.  
  18. // Calculate newHorizontalOffset.
  19. let newHorizontalOffset = ((currentPage + flickedPages ) * pageWidth) - scrollView.contentInset.left
  20.  
  21. targetContentOffset.pointee.x = newHorizontalOffset
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement