@@ -119,6 +119,15 @@ - (void)layoutSubviews
119119 }
120120}
121121
122+ - (void )addGestureRecognizer : (UIGestureRecognizer *)gestureRecognizer
123+ {
124+ if ([gestureRecognizer isKindOfClass: [UILongPressGestureRecognizer class ]]) {
125+ [gestureRecognizer addTarget: self action: @selector (slk_gestureRecognized: )];
126+ }
127+
128+ [super addGestureRecognizer: gestureRecognizer];
129+ }
130+
122131
123132#pragma mark - Getters
124133
@@ -405,24 +414,6 @@ - (void)layoutIfNeeded
405414 [super layoutIfNeeded ];
406415}
407416
408- - (NSArray *)gestureRecognizers
409- {
410- NSArray *gestureRecognizers = [super gestureRecognizers ];
411-
412- // Adds an aditional action to a private gesture to detect when the magnifying glass becomes visible
413- for (UIGestureRecognizer *gesture in gestureRecognizers) {
414- if ([gesture isMemberOfClass: NSClassFromString (@" UIVariableDelayLoupeGesture" )]) {
415-
416- NSArray *targets = [gesture valueForKeyPath: @" _targets" ];
417- if (targets.count > 0 ) {
418- [gesture addTarget: self action: @selector (slk_willShowLoupe: )];
419- }
420- }
421- }
422-
423- return gestureRecognizers;
424- }
425-
426417- (void )setSelectedRange : (NSRange )selectedRange
427418{
428419 [super setSelectedRange: selectedRange];
@@ -500,6 +491,31 @@ - (void)setTextAlignment:(NSTextAlignment)textAlignment
500491}
501492
502493
494+ #pragma mark - UITextInput Overrides
495+
496+ - (void )beginFloatingCursorAtPoint : (CGPoint)point
497+ {
498+ _trackpadEnabled = YES ;
499+ }
500+
501+ - (void )updateFloatingCursorAtPoint : (CGPoint)point
502+ {
503+ // Do something
504+ }
505+
506+ - (void )endFloatingCursor
507+ {
508+ _trackpadEnabled = NO ;
509+
510+ // We still need to notify a selection change in the textview after the trackpad is disabled
511+ if (self.delegate && [self .delegate respondsToSelector: @selector (textViewDidChangeSelection: )]) {
512+ [self .delegate textViewDidChangeSelection: self ];
513+ }
514+
515+ [[NSNotificationCenter defaultCenter ] postNotificationName: SLKTextViewSelectedRangeDidChangeNotification object: self userInfo: nil ];
516+ }
517+
518+
503519#pragma mark - UIResponder Overrides
504520
505521- (BOOL )canBecomeFirstResponder
@@ -592,13 +608,23 @@ - (void)paste:(id)sender
592608
593609#pragma mark - Custom Actions
594610
611+ - (void )slk_gestureRecognized : (UIGestureRecognizer *)gesture
612+ {
613+ // In iOS 8 and earlier, the gesture recognizer responsible for the magnifying glass movement was 'UIVariableDelayLoupeGesture'
614+ // Since iOS 9, that gesture is now called '_UITextSelectionForceGesture'
615+ if ([gesture isMemberOfClass: NSClassFromString (@" UIVariableDelayLoupeGesture" )] ||
616+ [gesture isMemberOfClass: NSClassFromString (@" _UITextSelectionForceGesture" )]) {
617+ [self slk_willShowLoupe: gesture];
618+ }
619+ }
620+
595621- (void )slk_willShowLoupe : (UIGestureRecognizer *)gesture
596622{
597- if (gesture.state == UIGestureRecognizerStateChanged) {
598- self. loupeVisible = YES ;
623+ if (gesture.state == UIGestureRecognizerStateBegan || gesture. state == UIGestureRecognizerStateChanged) {
624+ _loupeVisible = YES ;
599625 }
600626 else {
601- self. loupeVisible = NO ;
627+ _loupeVisible = NO ;
602628 }
603629
604630 // We still need to notify a selection change in the textview after the magnifying class is dismissed
0 commit comments