Search code examples
iosobjective-ciphoneswiftuitextview

UITextView did finish change selection


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.


Solution

  • 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.