Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
- tableView.reloadData()
- DispatchQueue.main.async {
- if targetContentOffset.pointee.y < scrollView.contentOffset.y {
- print("go up")
- print(self.currentRow)
- self.tableView.scrollToRow(at: NSIndexPath(row: self.currentRow-1, section: 0) as IndexPath, at: UITableView.ScrollPosition.top, animated: true)
- } else {
- print("go down")
- print(self.currentRow)
- self.tableView.scrollToRow(at: NSIndexPath(row: self.currentRow+1, section: 0) as IndexPath, at: UITableView.ScrollPosition.top, animated: true)
- self.currentRow += 1
- }
- }
- }
- var lastOffset: CGFloat = 0
- func scrollViewDidScroll(_ scrollView: UIScrollView) {
- let offset = scrollView.contentOffset.y
- if offset < lastOffset { // check offset difference
- NSLog("up")
- } else {
- NSLog("down")
- }
- lastOffset = offset // record last offset
- }
- var current:CGFloat = 0
- func scrollViewWillBeginDragging(scrollView: UIScrollView) {
- self.current = scrollView.contentOffset.y
- }
- func scrollViewDidScroll(_ scrollView: UIScrollView) {
- let contentOffset = scrollView.contentOffset.y
- if contentOffset > current {
- print("go up")
- }else if current > contentOffset{
- print("go down")
- }else{//
- }
- }
Add Comment
Please, Sign In to add comment