Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. /*
  2. * The issue this whole time was the UITextView would not wait for the pan gesture of it's hosting UIScrollView to fail.
  3. * Once we find out the correct gestures to hook into, we can ensure they don't get recognized simultaneously.
  4. */
  5.  
  6. @interface TextViewSubclass : UITextView <UIGestureRecognizerDelegate> {
  7. BOOL _hasHookedGesturesForiOS13LinkTapBug;
  8. }
  9.  
  10. - (void)_hookGestures;
  11.  
  12. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
  13.  
  14. @end
  15.  
  16. @implementation TextViewSubclass
  17.  
  18. - (void)_hookGestures {
  19. /*
  20. * as this can get called multiple times, we use a simple flag to keep it in check.
  21. */
  22. if (_hasHookedGesturesForiOS13LinkTapBug) {
  23. return;
  24. }
  25.  
  26. _hasHookedGesturesForiOS13LinkTapBug = YES;
  27.  
  28. Class longPress = UILongPressGestureRecognizer.class;
  29. Class linkTap = UITapGestureRecognizer.class;
  30.  
  31. for (UIGestureRecognizer *gesture in self.gestureRecognizers) {
  32.  
  33. if ([gesture isKindOfClass:longPress] || [gesture isKindOfClass:linkTap]) {
  34. gesture.delegate = self;
  35. }
  36.  
  37. }
  38.  
  39. }
  40.  
  41. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  42.  
  43. Class longPress = UILongPressGestureRecognizer.class;
  44. Class linkTap = UITapGestureRecognizer.class;
  45. Class scrollViewPan = NSClassFromString(@"UIScrollViewPanGestureRecognizer");
  46.  
  47. if ([gestureRecognizer isKindOfClass:longPress] || [gestureRecognizer isKindOfClass:linkTap]) {
  48. #ifdef DEBUG
  49. NSLog(@"Other gesture: %@", otherGestureRecognizer);
  50. #endif
  51. if ([otherGestureRecognizer isKindOfClass:scrollViewPan]) {
  52. return NO;
  53. }
  54.  
  55. return YES;
  56. }
  57.  
  58. return YES;
  59.  
  60. }
  61.  
  62. #pragma mark - Usage
  63.  
  64. - (void)setAttributedText:(NSAttributedString *)attributedText {
  65. [super setAttributedText:attributedText];
  66.  
  67. // we only need to call this on iOS 13.
  68. if (@avilable(iOS 13, *)) {
  69. [self _hookGestures];
  70. }
  71.  
  72. }
  73.  
  74. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement