Last active
May 7, 2018 18:42
-
-
Save glm4/dde8a525a1903d94ea94892cf99eb420 to your computer and use it in GitHub Desktop.
UIScrollView scrolling events detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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