Shorten the touch delay in a UIScrollView?

和自甴很熟 提交于 2019-12-04 19:00:29

问题


I'm looking to shorten the touch delay on a UIScrollView, but I don't want to use setDelaysContentTouches:NO; I still want there to be a slight delay but my users are complaining about it being too long.

Is there a way to do this?


回答1:


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.




回答2:


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;
}


来源:https://stackoverflow.com/questions/3080520/shorten-the-touch-delay-in-a-uiscrollview

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