IOS: Concept of positionFromPosition: inDirection: offset:

I am trying to implement my own UITextInput, however I am having problems updating the position using the cursor key on a bluetooth keyboard. I'm trying to create a TextInput that loops if you imagine the characters are numbered like this:

1 2 3
4 5 6
7 8 9

      

Then pushing at position 2 should take you to position 8 (pushing left on 6 will take you to 4, etc.). IOS seems to be calling positionFromPosition: inDirection: offset: to determine how to move from the current position. Then it calls setSelectedTextRange: to update the cursor position.

This is fine so far, but it seems that sometimes iOS doesn't call positionFromPosition: inDirection: offset: for example, if I press Up and then Down again, iOS seems to cache the previous position and just call setSelectedTextRange: with that the previous value. I don't understand this, is there a way to tell iOS that the selected position has changed and it should clear the cache i.e. If someone clicked the "clear" button or something else?

Caching seems to be used for the Up and Down cursor keys, moving left and right never caches the previous values ​​and the positionFromPosition: inDirection: offset: is always called. Even if I don't consider resetting the cursor position for something, I still have problems with "positionFromPosition: inDirection: offset:" that sometimes don't get called, and I just keep getting "setSelectedTextRange:" set by iOS to one value. So if it seems to me that I misunderstood something about how iOS caches cursor movement. Can anyone help me?

+3


source to share





All Articles