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