Skip to content

Instantly share code, notes, and snippets.

@glm4
Last active May 7, 2018 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glm4/dde8a525a1903d94ea94892cf99eb420 to your computer and use it in GitHub Desktop.
Save glm4/dde8a525a1903d94ea94892cf99eb420 to your computer and use it in GitHub Desktop.
UIScrollView scrolling events detection
extension UIScrollView {
//MARK: Normal Scrolling
func didScrollBeyondTop(withThreshold minimum: CGFloat = 0) -> Bool {
return contentOffset.y < -minimum
}
func didScrollBeyondBottom(withThreshold minimum: CGFloat = 0) -> Bool {
if contentOffset.y <= 0 { return false } //Fixes UIRefreshControll initial state
return contentOffset.y >= (contentSize.height - bounds.size.height) + minimum
}
func didScrollBeyondLeft(withThreshold minimum: CGFloat = 0) -> Bool {
return contentOffset.x < -minimum
}
func didScrollBeyondRight(withThreshold minimum: CGFloat = 0) -> Bool {
return contentOffset.x >= (contentSize.width - bounds.size.width) + minimum
}
//MARK: Paged Scrolling
func didReachLastVerticalPage() -> Bool {
return contentOffset.y >= (contentSize.height / frame.size.height - 1) * frame.size.height
}
func didReachLastHorizontalPage() -> Bool {
return contentOffset.x >= (contentSize.width / frame.size.width - 1) * frame.size.width
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment