我想,以取代RBSplitView
与NSSplitView
我现有的项目.该应用程序现在只有豹子,我想用Leopard附带RBSplitView
的新产品 替换NSSplitView
.
不过,我错过RBSplitView
的便利方法expand
和collapse
在NSSplitView
.如何以编程方式展开和折叠部分NSSplitView?
只需隐藏您想要折叠的子视图,例如
[aSubViewToCollapse setHidden:YES];
您可能还希望实现委托方法 - (BOOL)splitView:shouldHideDividerAtIndex:返回YES以在折叠时隐藏分隔符.
我刚刚进行了程序化扩展和崩溃NSSplitView
工作.NSSplitView
每当双击分割器时,我还配置了我的扩展/折叠子视图,所以我希望这对于该功能很好玩(似乎).这就是我做的:
(在这个例子中,splitView
是我NSSplitView
自己,splitViewSubViewLeft
是我希望展开/折叠的子视图,lastSplitViewSubViewLeftWidth
是一个类型的实例变量CGFloat
.)
// subscribe to splitView's notification of subviews resizing // (I do this in -(void)awakeFromNib) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mainSplitViewWillResizeSubviewsHandler:) name:NSSplitViewWillResizeSubviewsNotification object:splitView ]; // this is the handler the above snippet refers to - (void) mainSplitViewWillResizeSubviewsHandler:(id)object { lastSplitViewSubViewLeftWidth = [splitViewSubViewLeft frame].size.width; } // wire this to the UI control you wish to use to toggle the // expanded/collapsed state of splitViewSubViewLeft - (IBAction) toggleLeftSubView:(id)sender { [splitView adjustSubviews]; if ([splitView isSubviewCollapsed:splitViewSubViewLeft]) [splitView setPosition:lastSplitViewSubViewLeftWidth ofDividerAtIndex:0 ]; else [splitView setPosition:[splitView minPossiblePositionOfDividerAtIndex:0] ofDividerAtIndex:0 ]; }
我尝试了上面的解决方案,发现它不起作用,因为isSubviewCollapsed从未返回YES
这些建议的组合产生了有效的结果
if ([splitViewTop isHidden]) { [splitViewTop setHidden:NO]; [split setPosition:previousSplitViewHeight ofDividerAtIndex:0]; } else { [splitViewTop setHidden:YES]; } [split adjustSubviews];