Skip to content

Instantly share code, notes, and snippets.

@bocato
Last active March 3, 2017 13:53
Show Gist options
  • Save bocato/43023b58749c4a5106a4cb529c5acf0a to your computer and use it in GitHub Desktop.
Save bocato/43023b58749c4a5106a4cb529c5acf0a to your computer and use it in GitHub Desktop.
Get scroll direction from ScrollViiew.
typedef enum ScrollDirection {
ScrollDirectionNone,
ScrollDirectionRight,
ScrollDirectionLeft,
ScrollDirectionUp,
ScrollDirectionDown
} ScrollDirection;
@property ScrollDirection lastScrollDirection;
@property (nonatomic, assign) CGFloat lastContentOffset;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
self.lastScrollDirection = [self getScrollDirection:scrollView];
}
- (ScrollDirection)getScrollDirection:(UIScrollView *)scrollView {
ScrollDirection scrollDirection;
if (self.lastContentOffset > scrollView.contentOffset.x)
scrollDirection = ScrollDirectionRight;
else if (self.lastContentOffset < scrollView.contentOffset.x)
scrollDirection = ScrollDirectionLeft;
self.lastContentOffset = scrollView.contentOffset.x;
return scrollDirection;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment