Skip to content

Instantly share code, notes, and snippets.

@hudinwal
Created August 15, 2016 12:20
Show Gist options
  • Save hudinwal/8e3b49b5c4c06cdb0b3b26b7e2b35383 to your computer and use it in GitHub Desktop.
Save hudinwal/8e3b49b5c4c06cdb0b3b26b7e2b35383 to your computer and use it in GitHub Desktop.
extension ViewController : UIScrollViewDelegate,UITableViewDelegate {
func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let yInset = scrollView.contentInset.top
if scrollView.contentOffset.y > -topOffset && targetContentOffset.memory.y < -topOffset {
targetContentOffset.memory.y = scrollView.contentOffset.y
scrollView.setContentOffset(CGPointMake(0, -topOffset), animated: true)
}
else if -topOffset > targetContentOffset.memory.y && targetContentOffset.memory.y > (-topOffset + (topOffset - yInset)/2) {
targetContentOffset.memory.y = scrollView.contentOffset.y
scrollView.setContentOffset(CGPointMake(0, -topOffset), animated: true)
}
else if (-topOffset + (topOffset - yInset)/2) > targetContentOffset.memory.y {
targetContentOffset.memory.y = scrollView.contentOffset.y
scrollView.setContentOffset(CGPointMake(0, -yInset), animated: true)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment