Missing.Matter
Missing.Matter

Reputation: 123

Shorten the touch delay in a UIScrollView?

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?

Upvotes: 9

Views: 2766

Answers (2)

João Nunes
João Nunes

Reputation: 3761

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

Upvotes: 0

Zoleas
Zoleas

Reputation: 4879

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.

Upvotes: 3

Related Questions