iosuitextviewswift3.2

iOS: Scrolling text view to bottom programmatically creates a large white space after the text


I am trying to load the contents of a file to a TextView on viewDidLoad() of a ViewController. I want the user to see the last content loaded from the file, so I tried the solutions mentioned here.

let bottom = textView.contentSize.height - textView.bounds.size.height
textView.setContentOffset(CGPoint(x: 0, y: bottom), animated:true)

The textview will scroll down but creates a large white space if we scroll down again.


Solution

  • This minor change, resolved my issue:

    let bottom = CGPoint(x: 0, y: textView.contentSize.height - textView.frame.size.height)
    textView.setContentOffset(bottom, animated: false)
    

    Posting my answer, so that someone else find this helpful. Thanku all for the support.