Created
March 3, 2016 16:40
-
-
Save priore/334b465b2760ce6c5cfb to your computer and use it in GitHub Desktop.
Scroll direction pulses with a value sensitivity
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
| @interface ViewController () <UIScrollViewDelegate> | |
| { | |
| CGFloat initialContentOffset; | |
| CGFloat previousContentDelta; | |
| } | |
| @property (nonatomic, assign) CGFloat senseValue; | |
| @end | |
| @implementation ViewController | |
| - (void)viewDidLoad | |
| { | |
| [super viewDidLoad]; | |
| self.senseValue = 300; | |
| } | |
| #pragma mark - UIScollView Delegates | |
| - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView | |
| { | |
| initialContentOffset = scrollView.contentOffset.x; | |
| previousContentDelta = 0.f; | |
| } | |
| - (void)scrollViewDidScroll:(UIScrollView *)scrollView | |
| { | |
| CGFloat prevDelta = previousContentDelta; | |
| CGFloat delta = scrollView.contentOffset.x - initialContentOffset; | |
| if (fabs(delta - prevDelta) >= self.senseValue) { | |
| if (delta > 0.f && prevDelta <= 0.f) { | |
| // | |
| // scroll from right to left | |
| // | |
| } else if (delta < 0.f && prevDelta >= 0.f) { | |
| // | |
| // scroll from left to right | |
| // | |
| } | |
| previousContentDelta = delta; | |
| } | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment