[IOS] textView automatically scrolls to the bottom

UITextView text content doesn't start from the top

 

Reference: https://stackoverflow.com/questions/26835944/uitextview-text-content-doesnt-start-from-the-top

 

I am using this method:

  override func viewWillAppear(_ animated: Bool) {
        yourTextView.isScrollEnabled = false
        yourTextView.text = "....."
    }

    override func viewDidAppear(_ animated: Bool) {
        yourTextView.isScrollEnabled = true
    }

 

Principle: When a large amount of text is inserted, it will cause the page to scroll down, so in the viewWillAppear stage, first lock the scroll of the page, and then import the text so that it does not scroll down automatically. Then in the viewDidAppear stage, allow scrolling again

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326125312&siteId=291194637