Last active
March 3, 2017 13:53
-
-
Save bocato/43023b58749c4a5106a4cb529c5acf0a to your computer and use it in GitHub Desktop.
Get scroll direction from ScrollViiew.
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
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