Smooth UITextView auto scroll to bottom of frame

前端 未结 2 1558
梦毁少年i
梦毁少年i 2021-01-18 23:38

Im using Xcode 5.1.1 developing for ios7. As there is new text entering the UITextView, I would like it if the text went up, leaving room for the user to see the new text. I

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-19 00:18

    (Answered by a question edit. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )

    The OP wrote:

    Solution: The problem was that when text was getting inserted into the texview it scrolled to the top then called the scrollRangeToVisible which scrolled it to the bottom, which gave a bad animation and an unpleasant user experience. I solved this by disabling scroll before the text enters, and enabled it after the text was entered so it only calls the scrollRangeToVisible

    [textview scrollRangeToVisible:textview.selectedRange];
    textview.scrollEnabled= NO;
    textview.text = [textview.text stringByAppendingString:createdString];
    textview.scrollEnabled= YES;
    

提交回复
热议问题