Has anyone had any luck adopting UITextInteraction?
Selection changes made via touch work (mostly) as advertised, but changes made programmatically or via a physical keyboard do not.
I believe I've set this up properly. When adding a UITextInteraction to a custom text view that supports UITextInput, iOS installs the following interactions:
UITextInteraction
_UITextMenuLinkInteraction
UIContextMenuInteraction
_UIClickPresentationInteraction
_UIClickInteraction
UITextInteraction
UITextSelectionInteraction
UITextLoupeInteraction
UITextServicesInteraction
UITextIndirectKeyboardInteraction
The touch-related UI seems to work.
- Tapping on the custom text view causes it to become first responder. A UITextSelectionView is installed as a subview, and the caret appears on the screen at the correct location. The caret can be dragged to a new location as expected.
- Tapping a second time causes the Select/Select All menu to appear.
- Double-tapping causes a UITextRangeView to be added, along with the appropriate UISelectionGrabberDot and UISelectionGrabber instances and the Cut/Copy… menu appears as expected. Moving handles via touch also works.
However, when a physical keyboard like the Smart Folio is attached, pressing the arrow keys has no effect on the selection UI. The setSelectedTextRange: method is called, but the caret or selection handles do not update.
Similarly, invoking setSelectedTextRange: programmatically (and calling the appropriate selectionWillChange:/selectionDidChange: methods) does not cause the selection UI to update. For example, choosing Select from the text menu supplied by the interaction invokes the select: method defined in UIResponderStandardEditActions (which is as expected), but setting the selectedTextRange and notifying the inputDelegate has no effect.
Since UITextSelectionView and UITextRangeView are private classes, it's not possible to update them from setSelectedTextRange. Setting needsLayout doesn't seem to work either.
Is there another way to update the selection UI when setting the text selection programmatically or via a physical keyboard?
-Steve