UITextView always scrolls from the beginning when using scrollRangeToVisible ()

I am debugging UITextView

which logs my operation.

eg. If I press a special button on the screen, this one UITextView

will show which button I just pressed. It will record more as I pressed more buttons, so I can easily scroll UITextView

to see my past operation.

Because it UITextView

itself does not scroll as the text grows, so I try to make it scroll to the last line when something is written to it. I am trying to use the scrollRangeToVisible () method below

history.scrollRangeToVisible(NSMakeRange(count(history.text!) - 1, 1))

      

Here, history is the way out UITextView

.

The problem is that this method always scrolls UITextView

from start to destination NSRange

. Specifically, this will reset the view of the start of the text and then scroll down to where it is NSRange

. I want him scroll

straight down,

Can someone fix this problem? Many thanks.

+3


source to share


1 answer


This link ( what to use instead of scrollRangeToVisible in iOS7 or TextKit ) suggests disabling scrolling, commit change, and enable it.

history.scrollEnabled = NO;
[history scrollRangeToVisible:NSMakeRange(history.text.length - 1,0)];
history.scrollEnabled = YES;

      

EDIT



Solved after discussion using:

history.layoutManager.allowsNonContiguousLayout = NO; 

      

Saw it here: UITextView setText shouldn't go to ios8

+5


source







All Articles