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
Written by Noval Agung Prayogo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ios
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#