Search code examples
iosiphoneuitextfield3dtouch

Capture iOS 3D Touch cursor


In iOS when you 3D Touch on the iPhone keyboard it allows for moving the cursor around the text field. I would like to build a text field from scratch and have similar feature. Is it possible to capture this event?


Solution

  • If you implement the UITextInput protocol, these messages will give you the info about the "floating cursor" events:

    func beginFloatingCursor(at: CGPoint)
    

    Called at the beginning of the gesture that the system uses to manipulate the cursor.

    func updateFloatingCursor(at: CGPoint)
    

    Called to move the floating cursor to a new location.

    func endFloatingCursor()
    

    Called at the end of the gesture that the system uses to manipulate the cursor