NSOutlineView expand / collapse animation from code

我是研究僧i 提交于 2019-12-06 03:17:49

问题


i'm wondering how does one animate the expansion/collapse of an NSOutlineView's tree node from code ?

// this works ok but doesn't animate  

NSTreeNode *node = [self.outlineView itemAtRow:self.outlineView.clickedRow];

if([self.outlineView isItemExpanded:node])
{
    [self.outlineView.animator collapseItem:node];
}else{
    [self.outlineView.animator expandItem:node];
}

an outline view naturally animates if you expand a node via the default-drawn arrow
so there IS a way...


回答1:


My original code was OK, this just wasn't available under 10.7

Original text from Application Kit Release Notes for OS X v10.8 :

NSOutlineView

The following methods now support being animated via the -animator proxy: -expandItem:, -expandItem:expandChildren:, -collapseItem:, and -collapseItem:collapseChildren:. As an example, to animate the expansion of a particular item: [[outlineView animator] expandItem:item];




回答2:


The problem is likely the node you are passing to collapseItem:. You need to pass the object your tree controller uses to represent the node rather than the actual node from your data model. If you are using NSTreeController, then you need to traverse the structure returned from -[NSTreeController arrangedObjects] to locate the node that represents your data model object.



来源:https://stackoverflow.com/questions/13881034/nsoutlineview-expand-collapse-animation-from-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!