Last active
March 18, 2019 11:30
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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