Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * The issue this whole time was the UITextView would not wait for the pan gesture of it's hosting UIScrollView to fail.
- * Once we find out the correct gestures to hook into, we can ensure they don't get recognized simultaneously.
- */
- @interface TextViewSubclass : UITextView <UIGestureRecognizerDelegate> {
- BOOL _hasHookedGesturesForiOS13LinkTapBug;
- }
- - (void)_hookGestures;
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
- @end
- @implementation TextViewSubclass
- - (void)_hookGestures {
- /*
- * as this can get called multiple times, we use a simple flag to keep it in check.
- */
- if (_hasHookedGesturesForiOS13LinkTapBug) {
- return;
- }
- _hasHookedGesturesForiOS13LinkTapBug = YES;
- Class longPress = UILongPressGestureRecognizer.class;
- Class linkTap = UITapGestureRecognizer.class;
- for (UIGestureRecognizer *gesture in self.gestureRecognizers) {
- if ([gesture isKindOfClass:longPress] || [gesture isKindOfClass:linkTap]) {
- gesture.delegate = self;
- }
- }
- }
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
- Class longPress = UILongPressGestureRecognizer.class;
- Class linkTap = UITapGestureRecognizer.class;
- Class scrollViewPan = NSClassFromString(@"UIScrollViewPanGestureRecognizer");
- if ([gestureRecognizer isKindOfClass:longPress] || [gestureRecognizer isKindOfClass:linkTap]) {
- #ifdef DEBUG
- NSLog(@"Other gesture: %@", otherGestureRecognizer);
- #endif
- if ([otherGestureRecognizer isKindOfClass:scrollViewPan]) {
- return NO;
- }
- return YES;
- }
- return YES;
- }
- #pragma mark - Usage
- - (void)setAttributedText:(NSAttributedString *)attributedText {
- [super setAttributedText:attributedText];
- // we only need to call this on iOS 13.
- if (@avilable(iOS 13, *)) {
- [self _hookGestures];
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement