12
我试图在我实现的聊天历史视图中实现平滑滚动,但是如果我追加的内容足够大,则平滑滚动只会滚动几行。NSTextView,附加文本和平滑滚动
我的第一个猜测是,该视图并没有重新绘制自己..不是这样,即使强制即时绘图使用-display它仍然中断。
- (void)scrollAnimated:(BOOL)animated
{
if(animated)
{
NSClipView *clipView = [[_chatHistoryView enclosingScrollView] contentView];
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.100f];
NSPoint constrainedPoint = [clipView constrainScrollPoint:NSMakePoint(0, CGFLOAT_MAX)];
[[clipView animator] setBoundsOrigin:constrainedPoint];
[NSAnimationContext endGrouping];
}
else
{
NSRange range;
range.location = [[_chatHistoryView textStorage] length];
range.length = 1;
[_chatHistoryView scrollRangeToVisible:range];
}
}
我在做什么错?
我敢肯定,这不会解决你的问题,但在非动画代码的范围会出界,因为它将以+ 1结束。 – mattmook 2012-10-29 01:34:33
在使用该代码一段时间后,我可能不得不查看文档为什么最后一个字符的位置(1)(因为长度是(我猜的位置+ 1))被接受。 – 2012-10-29 11:52:53