变更记录

序号 录入时间 录入人 备注
1 2016-03-09 Alfred Jiang -

方案名称

UITextView - 添加内容后自动滚动到最后一行

关键字

UITextView \ 动态添加 \ 自动滚动

需求场景

  1. 向 UITextView 中动态添加内容并希望自动滚动到底部时

参考链接

  1. CSDN - UITextView内容添加后,自动滚动到最后一行

详细内容

1. 设置 layoutManager.allowsNonContiguousLayout 属性为 NO
self.textViewInfo.layoutManager.allowsNonContiguousLayout = NO; //这句代码设置了 UITextView 中的 layoutManager(NSLayoutManager) 的是否非连续布局属性,默认是 YES,设置为 NO 后 UITextView 就不会再自己重置滑动了。
2. 执行 scrollRangeToVisible 方法, 滑动到底部
[self.textViewInfo scrollRangeToVisible:NSMakeRange(self.textViewInfo.text.length, 1)];

效果图

(无)

备注

(无)

results matching ""

    No results matching ""