简体   繁体   中英

Cursor position not same after remove text in a UITextView

I'm looking for solution for this problem. I want my cursor to be at the starting position normally.

I have a UITextView , which the users can input a message and send it. But when users send the message, or they just remove the text in UITextView , the beginning of the cursor(blinking bar) is not the same position, the position depends on the length of the text they had sent or removed. If the text is only 1 line, the cursor position will be in the top left corner of UITextView , otherwise, if the text is longer than 1 line, the cursor position will be in the bottom left corner of UITextView .

I tried both setMarkedText after becomeFirstResponder() and automaticallyAdjustsScrollIndicatorInsets but it still not work.

More Info:

In the first time touch in this UITextView, the cursor jumps from center vertically to top left corner too.

You can add a UILabel over the UITextView which will act as a placeholder for the textView. When user taps on the UILabel would send the action to the textView and makes it becomeFirstResponder. When you start typing, make the label hidden.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM