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];
}
}
我做错了什么?
I am trying to implement smooth scrolling in a chat history view I implemented, however if the content I append is big enough the smooth scroll will only scroll for a few lines.
My first guess was that the view did not redraw itself yet.. not the case, even when forcing immediate drawing with -display it still breaks.
- (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];
}
}
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能会帮助你...
}
This may help you...
}