Created
January 8, 2014 14:27
-
-
Save Abeansits/8317545 to your computer and use it in GitHub Desktop.
A category on UIScrollView for detecting when content has scrolled to top or bottom.
This file contains hidden or 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
// | |
// UIScrollView+Extensions.h | |
// | |
// | |
@interface UIScrollView (Extensions) | |
/// Returns true if the content has been scrolled all the way to the top (by pulling the content up). | |
- (BOOL)isScrolledToTop; | |
/// Returns true if the content has been scrolled all the way to the bottom (by pulling the content down). | |
- (BOOL)isScrolledToBottom; | |
@end |
This file contains hidden or 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
// | |
// UIScrollView+Extensions.m | |
// | |
// | |
#import "UIScrollView+Extensions.h" | |
@implementation UIScrollView (Extensions) | |
- (BOOL)isScrolledToTop { | |
return (self.contentOffset.y <= [self verticalOffsetToTop]); | |
} | |
- (BOOL)isScrolledToBottom { | |
return (self.contentOffset.y >= [self verticalOffsetToBottom]); | |
} | |
#pragma mark - Utils | |
- (CGFloat)verticalOffsetToTop { | |
CGFloat verticalOffsetTop = self.contentInset.top; | |
return -verticalOffsetTop; | |
} | |
- (CGFloat)verticalOffsetToBottom { | |
CGFloat verticalOffsetBottom = (self.contentSize.height + self.contentInset.bottom - self.bounds.size.height); | |
return verticalOffsetBottom; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment