问题描述
我想实现一个动作滚动到NSTableView的顶部,和NSTableView的底部。我使用 scrollRowToVisible
但我喜欢的动作是动画。有没有办法做到这一点?
I am trying to implement an action to scroll to the top of a NSTableView, and the bottom of the NSTableView. I am using scrollRowToVisible
but I'd love the action to be animated. Is there a way to do this?
推荐答案
虽然NSTableView没有滚动属性可以直接进行动画, ,有一点数学动画滚动的NSClipView的NSTableView生活。
While the NSTableView does not have a scroll property you can directly animate, you can instead, with a bit of math animate the scrolling of the NSClipView that the NSTableView lives in.
这是我做的这一点(在NSTableView的自定义子类中)平滑地动画如果可能的话,rowIndex的行滚动到视图的中心:
Here is how I did this (within a custom subclass of NSTableView) to smoothly animate the row at rowIndex to be scrolled to the center of the view, if possible:
NSRect rowRect = [self rectOfRow:rowIndex];
NSRect viewRect = [[self superview] frame];
NSPoint scrollOrigin = rowRect.origin;
scrollOrigin.y = scrollOrigin.y + (rowRect.size.height - viewRect.size.height) / 2;
if (scrollOrigin.y < 0) scrollOrigin.y = 0;
[[[self superview] animator] setBoundsOrigin:scrollOrigin];
这篇关于NSTableView scrollRowToVisible与动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!