daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Dec 15th, 2018 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
  2.     tableView.reloadData()
  3.  
  4.     DispatchQueue.main.async {
  5.  
  6.         if targetContentOffset.pointee.y < scrollView.contentOffset.y {
  7.             print("go up")
  8.             print(self.currentRow)
  9.             self.tableView.scrollToRow(at: NSIndexPath(row: self.currentRow-1, section: 0) as IndexPath, at: UITableView.ScrollPosition.top, animated: true)
  10.  
  11.         } else {
  12.             print("go down")
  13.             print(self.currentRow)
  14.             self.tableView.scrollToRow(at: NSIndexPath(row: self.currentRow+1, section: 0) as IndexPath, at: UITableView.ScrollPosition.top, animated: true)
  15.             self.currentRow += 1
  16.         }
  17.     }
  18. }
  19.    
  20. var lastOffset: CGFloat = 0
  21.  
  22. func scrollViewDidScroll(_ scrollView: UIScrollView) {
  23.  
  24.     let offset = scrollView.contentOffset.y
  25.  
  26.     if offset < lastOffset { // check offset difference
  27.         NSLog("up")
  28.     } else {
  29.         NSLog("down")
  30.     }
  31.     lastOffset = offset // record last offset
  32.  
  33. }
  34.    
  35. var current:CGFloat = 0
  36.  func scrollViewWillBeginDragging(scrollView: UIScrollView) {
  37.     self.current = scrollView.contentOffset.y
  38.  }
  39.  
  40.  func scrollViewDidScroll(_ scrollView: UIScrollView) {
  41.     let contentOffset = scrollView.contentOffset.y
  42.     if contentOffset > current {
  43.         print("go up")
  44.     }else if current > contentOffset{
  45.         print("go down")
  46.     }else{//
  47.     }
  48.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top