I'm debugging a UITextView
which logs my operation.
e.g. If I press a special button on the screen, this UITextView
will show which button I just pressed. It will log more as I pressed more buttons, so I can easily scroll the UITextView
to see my past operation.
Because the UITextView
itself doesn't scroll with increasing text, so I try to make it scroll to the last line when something is logged into it.
I try to use the scrollRangeToVisible() method below
history.scrollRangeToVisible(NSMakeRange(count(history.text!) - 1, 1))
Here history is a UITextView
outlet.
The problem is, this method always makes the UITextView
to scroll from the beginning to the designated NSRange
. More specifically, it will reset the view to the beginning of the text and then scroll down to wherever the NSRange
is. I want it to scroll
directly down,
Can someone solve this problem? Thanks a lot.
This link (what to use instead of scrollRangeToVisible in iOS7 or TextKit) suggests turning scrolling off, do the change then switch it on.
history.scrollEnabled = NO;
[history scrollRangeToVisible:NSMakeRange(history.text.length - 1,0)];
history.scrollEnabled = YES;
EDIT
Solved after discussion using:
history.layoutManager.allowsNonContiguousLayout = NO;
Saw this here: UITextView setText should not jump to top in ios8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With