Reputation: 1198
I am using a UITextView
. I want to autoscroll the textview's text with animation from top to bottom for one time. How can I achieve this?
Upvotes: 1
Views: 552
Reputation: 1698
Try this:
Swift:
let range = NSMakeRange(textView.text.characters.count - 1, 0)
textView.scrollRangeToVisible(range)
Objective C:
NSRange range = NSMakeRange(textView.text.length -1, 1);
[textView scrollRangeToVisible:range];
Upvotes: 0
Reputation: 1874
try this
if(textView.text.length > 0 ) {
NSRange bottom = NSMakeRange(textView.text.length -1, 1);
[textView scrollRangeToVisible:bottom];
}
Upvotes: 0
Reputation: 58049
You should animate the UITextView
's contentOffset
property.
Objective-C
[UIView animateWithDuration:{duration} animations:^{
[textView setContentOffset:CGPointMake(0, textView.contentSize.height - textView.frame.size.height)];
}]
Swift
UIView.animate(withDuration: {duration}) {
textView.setContentOffset(CGPoint(x: 0, y: textView.contentSize.height - textView.frame.height), animated: false)
}
Upvotes: 3