How to directly call up the system's text selection view in iOS 17 and above without double-clicking or long-pressing once #138620
Replies: 2 comments 1 reply
-
who can help me |
Beta Was this translation helpful? Give feedback.
-
In iOS 17, simply setting the selectedTextRange programmatically no longer triggers the text selection menu by default. To make the selection controls appear, you need to: Ensure your label becomes the first responder using becomeFirstResponder.
|
Beta Was this translation helpful? Give feedback.
-
Body
**Background: **
We have customized a UIView that implements the UITextInput protocol, aiming to enable "partial text selection." Currently, this functionality works as expected through double-tap or long-press gestures. However, our goal is to allow users to trigger text selection by clicking a button instead of relying on double-tap or long-press actions.
**Current Implementation: **
To achieve this, we have designed the following implementation. When the button is clicked, the following code is executed:
[self.customTextLabel becomeFirstResponder];
[self.customTextLabel.m_inputDelegate selectionWillChange:self.customTextLabel];
UITextPosition *start = [self.customTextLabel beginningOfDocument];
UITextPosition *end = [self.customTextLabel endOfDocument];
UITextRange *range = [self.customTextLabel textRangeFromPosition:start toPosition:end];
self.customTextLabel.selectedTextRange = range;
[self.customTextLabel.m_inputDelegate selectionDidChange:self.customTextLabel];
**Issue: **
On systems prior to iOS 17, this code correctly triggers the system's "partial selection" view. However, on iOS 17 and later, the selection view does not appear when this code is executed. It only appears if the user has previously triggered the selection view via long-press or double-tap, and then runs this code.
Request:
We would like to know how to trigger the "partial selection" view directly by executing the above code on iOS 17 and later, without requiring the user to first use double-tap or long-press.
Hypothesis:
We observed that when similar code is executed on a system UITextField, it does correctly trigger the "partial selection" view. This leads us to suspect that there might be some protocol implementations or additional method calls that we are missing.
Specific demo:
iOS.15.4.MP4
iOS.17.0.MP4
https://github.com/aimei111/testSelect.git
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions