iPhone SDK: How to create a UITextView that inserts text where you tap?

后端 未结 1 1316
失恋的感觉
失恋的感觉 2021-02-06 16:37

I\'d like to create a UITextView that you can tap anywhere within it and start typing at that location. The default behavior of the control is that typing starts where the last

1条回答
  •  不知归路
    2021-02-06 17:36

    I suggest deriving from UITextView to create a custom view that handles taps. You'll want to override the following methods, probably:

    • touchesBegan:withEvent
    • touchesMoved:withEvent
    • touchesEnded:withEvent
    • touchesCancelled:withEvent

    Make sure the userInteractionEnabled property has a default value of YES. Override hitTest:withEvent and pointInside:withEvent to figure out where in your view the user tapped.

    Be sure and read the Responding to Events section in the View Programming Guide for iOS, and also see the Event Handling Guide for iOS for more details.

    Anyway, once you figure out where the user touched, you can modify the text or reposition the karat as appropriate.

    0 讨论(0)
提交回复
热议问题