Advertisement
priore

Scroll direction pulses with a value sensitivity

Mar 3rd, 2016
1,102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @interface ViewController () <UIScrollViewDelegate>
  2. {
  3.     CGFloat initialContentOffset;
  4.     CGFloat previousContentDelta;
  5. }
  6.  
  7. @property (nonatomic, assign) CGFloat senseValue;
  8.  
  9. @end
  10.  
  11. @implementation ViewController
  12.  
  13. - (void)viewDidLoad
  14. {
  15.     [super viewDidLoad];
  16.    
  17.     self.senseValue = 300;
  18. }
  19.  
  20. #pragma mark - UIScollView Delegates
  21.  
  22. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  23. {
  24.     initialContentOffset = scrollView.contentOffset.x;
  25.     previousContentDelta = 0.f;
  26. }
  27.  
  28. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  29. {
  30.     CGFloat prevDelta = previousContentDelta;
  31.     CGFloat delta = scrollView.contentOffset.x - initialContentOffset;
  32.    
  33.     if (fabs(delta - prevDelta) >= self.senseValue) {
  34.         if (delta > 0.f && prevDelta <= 0.f) {
  35.             //
  36.             // scroll from right to left
  37.             //
  38.         } else if (delta < 0.f && prevDelta >= 0.f) {
  39.             //
  40.             // scroll from left to right
  41.             //
  42.         }
  43.        
  44.         previousContentDelta = delta;
  45.     }
  46. }
  47.  
  48. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement