2sid0q
Last Updated: February 25, 2016
·
7.439K
· novalagung
16162fed91387cc1cec055412db0022d

iOS - Remove UIButton touch delay inner UIScrollView

when you placed UIButton inner UIScrollView, you will notice some strange behaviour in the button. the button need some delay to become highlighted, due to touch target detection, is it for button, or for scrollview swipe.

you can use some trick to remove the delay.

  • first, in storyboard, uncheck Delay Content Touches attribute of scrollView
  • second, subclass the UIScrollView, and implements these code :
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.delaysContentTouches = NO;
    }

    return self;
}

- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
    if ([view isKindOfClass:UIButton.class]) {
        return YES;
    }

    return [super touchesShouldCancelInContentView:view];
}

reference : http://stackoverflow.com/a/19656611/1467988

Say Thanks
Respond