Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Source/Classes/SLKTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ typedef NS_OPTIONS(NSUInteger, SLKPastableMediaType) {
/** YES if the magnifying glass is visible. */
@property (nonatomic, getter=isLoupeVisible) BOOL loupeVisible;

/** YES if the keyboard track pad has been recognized. iOS 9 only. */
@property (nonatomic, readonly, getter=isTrackpadEnabled) BOOL trackpadEnabled;

/** YES if autocorrection and spell checking are enabled. On iOS8, this property also controls the predictive QuickType bar from being visible. Default is YES. */
@property (nonatomic, getter=isTypingSuggestionEnabled) BOOL typingSuggestionEnabled;

Expand Down
68 changes: 47 additions & 21 deletions Source/Classes/SLKTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ - (void)layoutSubviews
}
}

- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) {
[gestureRecognizer addTarget:self action:@selector(slk_gestureRecognized:)];
}

[super addGestureRecognizer:gestureRecognizer];
}


#pragma mark - Getters

Expand Down Expand Up @@ -405,24 +414,6 @@ - (void)layoutIfNeeded
[super layoutIfNeeded];
}

- (NSArray *)gestureRecognizers
{
NSArray *gestureRecognizers = [super gestureRecognizers];

// Adds an aditional action to a private gesture to detect when the magnifying glass becomes visible
for (UIGestureRecognizer *gesture in gestureRecognizers) {
if ([gesture isMemberOfClass:NSClassFromString(@"UIVariableDelayLoupeGesture")]) {

NSArray *targets = [gesture valueForKeyPath:@"_targets"];
if (targets.count > 0) {
[gesture addTarget:self action:@selector(slk_willShowLoupe:)];
}
}
}

return gestureRecognizers;
}

- (void)setSelectedRange:(NSRange)selectedRange
{
[super setSelectedRange:selectedRange];
Expand Down Expand Up @@ -500,6 +491,31 @@ - (void)setTextAlignment:(NSTextAlignment)textAlignment
}


#pragma mark - UITextInput Overrides

- (void)beginFloatingCursorAtPoint:(CGPoint)point
{
_trackpadEnabled = YES;
}

- (void)updateFloatingCursorAtPoint:(CGPoint)point
{
// Do something
}

- (void)endFloatingCursor
{
_trackpadEnabled = NO;

// We still need to notify a selection change in the textview after the trackpad is disabled
if (self.delegate && [self.delegate respondsToSelector:@selector(textViewDidChangeSelection:)]) {
[self.delegate textViewDidChangeSelection:self];
}

[[NSNotificationCenter defaultCenter] postNotificationName:SLKTextViewSelectedRangeDidChangeNotification object:self userInfo:nil];
}


#pragma mark - UIResponder Overrides

- (BOOL)canBecomeFirstResponder
Expand Down Expand Up @@ -592,13 +608,23 @@ - (void)paste:(id)sender

#pragma mark - Custom Actions

- (void)slk_gestureRecognized:(UIGestureRecognizer *)gesture
{
// In iOS 8 and earlier, the gesture recognizer responsible for the magnifying glass movement was 'UIVariableDelayLoupeGesture'
// Since iOS 9, that gesture is now called '_UITextSelectionForceGesture'
if ([gesture isMemberOfClass:NSClassFromString(@"UIVariableDelayLoupeGesture")] ||
[gesture isMemberOfClass:NSClassFromString(@"_UITextSelectionForceGesture")]) {
[self slk_willShowLoupe:gesture];
}
}

- (void)slk_willShowLoupe:(UIGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateChanged) {
self.loupeVisible = YES;
if (gesture.state == UIGestureRecognizerStateBegan || gesture.state == UIGestureRecognizerStateChanged) {
_loupeVisible = YES;
}
else {
self.loupeVisible = NO;
_loupeVisible = NO;
}

// We still need to notify a selection change in the textview after the magnifying class is dismissed
Expand Down
9 changes: 8 additions & 1 deletion Source/Classes/SLKTextViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,14 @@ - (void)textSelectionDidChange
}

// Skips if the loupe is visible or if there is a real text selection
if (self.textView.isLoupeVisible || self.textView.selectedRange.length > 0) {
if (self.textView.isLoupeVisible || self.textView.isTrackpadEnabled) {
return;
}

if (self.textView.selectedRange.length > 0) {
if (self.isAutoCompleting) {
[self cancelAutoCompletion];
}
return;
}

Expand Down