Skip to content

Instantly share code, notes, and snippets.

@Abeansits
Created January 8, 2014 14:27
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Abeansits/8317545 to your computer and use it in GitHub Desktop.
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.
//
// 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
//
// 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