使用 scrollRangeToVisible() 时,UITextView 总是从头开始滚动
UITextView always scrolls from the beginning when using scrollRangeToVisible()
我正在调试记录我的操作的 UITextView
。
例如如果我按下屏幕上的一个特殊按钮,这个 UITextView
将显示我刚刚按下的按钮。当我按下更多按钮时,它会记录更多,因此我可以轻松滚动 UITextView
查看我过去的操作。
因为 UITextView
本身不会随着文本的增加而滚动,所以我尝试让它在登录时滚动到最后一行。
我尝试使用下面的scrollRangeToVisible()方法
history.scrollRangeToVisible(NSMakeRange(count(history.text!) - 1, 1))
这里的历史是一个UITextView
出口。
问题是,这个方法总是让UITextView
从头开始滚动到指定的NSRange
。更具体地说,它将视图重置为文本的开头,然后向下滚动到 NSRange
所在的位置。我要scroll
直接往下,
有人可以解决这个问题吗?非常感谢。
这个 link (what to use instead of scrollRangeToVisible in iOS7 or TextKit) 建议关闭滚动,进行更改然后打开它。
history.scrollEnabled = NO;
[history scrollRangeToVisible:NSMakeRange(history.text.length - 1,0)];
history.scrollEnabled = YES;
编辑
讨论后解决使用:
history.layoutManager.allowsNonContiguousLayout = NO;
在这里看到这个:UITextView setText should not jump to top in ios8
我正在调试记录我的操作的 UITextView
。
例如如果我按下屏幕上的一个特殊按钮,这个 UITextView
将显示我刚刚按下的按钮。当我按下更多按钮时,它会记录更多,因此我可以轻松滚动 UITextView
查看我过去的操作。
因为 UITextView
本身不会随着文本的增加而滚动,所以我尝试让它在登录时滚动到最后一行。
我尝试使用下面的scrollRangeToVisible()方法
history.scrollRangeToVisible(NSMakeRange(count(history.text!) - 1, 1))
这里的历史是一个UITextView
出口。
问题是,这个方法总是让UITextView
从头开始滚动到指定的NSRange
。更具体地说,它将视图重置为文本的开头,然后向下滚动到 NSRange
所在的位置。我要scroll
直接往下,
有人可以解决这个问题吗?非常感谢。
这个 link (what to use instead of scrollRangeToVisible in iOS7 or TextKit) 建议关闭滚动,进行更改然后打开它。
history.scrollEnabled = NO;
[history scrollRangeToVisible:NSMakeRange(history.text.length - 1,0)];
history.scrollEnabled = YES;
编辑
讨论后解决使用:
history.layoutManager.allowsNonContiguousLayout = NO;
在这里看到这个:UITextView setText should not jump to top in ios8