I want to catch event when user finish change selection in UITextView. Method textViewDidChangeSelection:
call a few times while user pulls cursor. I try to use touchesEnded:withEvent:
, but it doesn't call. Try to add pan gesture, but pan handler don't call.
UITextInputDelegate
's selectionDidChange(_:)
is called when the user has finished changing the selection (lifts their finger from the selection handles). On the UITextView
, set your class as the inputDelegate
. This works for read-only text views, not just editable ones.
I know it's too late to answer.
Though..
You can use selectedRange
inside textViewDidChangeSelection:
and check if selectedRange.length
is greater than zero. This will confirm that user has selected something and not just moved the cursor.
length
> 0. I need somehow handle when user touch up his finger. –
Aquiculture UITextInputDelegate
's selectionDidChange(_:)
is called when the user has finished changing the selection (lifts their finger from the selection handles). On the UITextView
, set your class as the inputDelegate
. This works for read-only text views, not just editable ones.
I think you'll have to subclass UITextView
and implement touchesEnded:withEvent:
in order to know when the user stops changing the selection.
It's a little bit of hack.
I've observed that after user lift his finger, system will call delegate querying about menu options, such as:
optional func textView(_ textView: UITextView, editMenuForTextIn range: NSRange, suggestedActions: [UIMenuElement]) -> UIMenu?
We can make good use of it, right?
Notice it only avaliable above iOS16.0
© 2022 - 2024 — McMap. All rights reserved.
textViewDidChangeSelection:
. – RobintextViewDidChangeSelection:
call. – Exurbanite