简体   繁体   中英

Scroll bug using UITextView in iOS 8.1 (iPad 2)

The problem which I have is same as: Smooth UITextView auto scroll to bottom of frame

Basically, when I use the auto scroll feature when appending a text to an existing text in UITextView, the scroll works, but it always goes to top then scroll all the way to bottom (which is a problem for big texts, or a chat room)

When I try the solution of this guy, which was :

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

So, I found a bug where it seems that the 'textview.scrollEnabled' never gets back to YES, so the scroll will simply never work.

I either have that weird scrolling where it gets back to top then to bottom or the other bug where the scrolling enabled never gets back to YES.

This should work for you. Get rid of the textView.scrollEnabled = NO; .

So your just left with:

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

and add this to your viewDidLoad:

textview.layoutManager.allowsNonContiguousLayout = NO;

I had similar problem too where scroll works fine in iOS 7 and iOS 9 but not in iOS 8. So, I found solution for scrolling to work in iOS 8 is:

NSString *strValue = [NSString stringWithFormat:@"Your text"];
txtVwObj.text = strValue; // If in your case text needs to give before scroll disable.
txtVwObj.scrollEnabled = NO;

// and set whatever you need for UITextView properties. 
// at last add the following code snippet.
 txtVwObj.scrollEnabled = YES;
 txtVwObj.text = @"";
 txtVwObj.text = [txtVwObj.text stringByAppendingString:strValue];

Hope it will help you.

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