Shorten the touch delay in a UIScrollView?

◇◆丶佛笑我妖孽 提交于 2019-12-03 12:36:26

The doc says

If the user then drags their finger far enough before the timer elapses, the scroll view cancels any tracking in the subview and performs the scrolling itself. Subclasses can override the touchesShouldBegin:withEvent:inContentView:, pagingEnabled, and touchesShouldCancelInContentView: methods (which are called by the scroll view) to affect how the scroll view handles scrolling gestures.

So i think there is no easy way to do it. You probably have to reimplement the whole timer system in those methods.

I just came across this problem and this is my solution:

Subclass UIScrolView

Add override these methods:

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{


    self.lastTimestamp = [NSDate date];

    return [super touchesShouldBegin:touches withEvent:event inContentView:view];
}

- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
      NSDate *now = [NSDate date];


     if (-[self.lastTimestamp timeIntervalSinceDate:now] < _delay)
        return YES;

    return NO;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!