Last Updated: February 25, 2016
·
1.317K
· Andrej Mihajlov

Fix touch delay on controls in scroll views

All subclasses of UIScrollView will delay touch delivery to any UIControls inside.

This delay is about 1 second and creates a sensible stutter. There is a simple fix that additionally adds a feature to cancel touch on control if it turned into panning.

@implementation MYCollectionView

- (id)initWithCoder:(NSCoder *)aDecoder {
    if(self = [super initWithCoder:aDecoder]) {
        // Disable touch delays to avoid highlighting delay on UIControls
        self.delaysContentTouches = NO;
    }
    return self;
}

- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
    // Cancel tap on UIControls if user moved finger
    return YES;
}

@end