Skip to content

Instantly share code, notes, and snippets.

@DEAD10CC
Last active March 18, 2019 11:30
Show Gist options
  • Select an option

  • Save DEAD10CC/533968c67ca34b84770778113fe46a85 to your computer and use it in GitHub Desktop.

Select an option

Save DEAD10CC/533968c67ca34b84770778113fe46a85 to your computer and use it in GitHub Desktop.
Setting delaysContentTouches = NO on a scroll view allows buttons within the scroll view to react on touches instantly. However, if you touch within the button's bounds to start scrolling, nothing happens. By overriding this method in a scroll view subclass, you can have best of both worlds: instant button tap and scrolling recognition.
// Credits go to http://charlesharley.com/2013/programming/uibutton-in-uitableviewcell-has-no-highlight-state
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
// Because we set delaysContentTouches = NO, we return YES for UIButtons
// so that scrolling works correctly when the scroll gesture
// starts in the UIButtons.
if ([view isKindOfClass:[UIButton class]]) {
return YES;
}
return [super touchesShouldCancelInContentView:view];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment