0
点赞
收藏
分享

微信扫一扫

[IOS]textView自动滚动到底部

Mhhao 2022-08-04 阅读 123


UITextView text content doesn't start from the top

 

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

 

我使用的是这种方法:



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


}

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



 

原理:当插入大量文本,会导致页面scroll向下,所以在viewWillAppear阶段先锁定页面的scroll,然后导入文本,使其不自动向下scroll。然后在viewDidAppear阶段,再允许scroll

举报

相关推荐

0 条评论