问题描述
我想在现有项目中将 RBSplitView
替换为 NSSplitView
。该应用程序现在仅是豹子,我想用 new NSSplitView
替换 RBSplitView
I want to replace RBSplitView
with NSSplitView
in my existing project. The application is now leopard only and I would like to replace RBSplitView
with the new NSSplitView
shipped with Leopard.
但是,我缺少 RBSplitView
方便的方法 expand
和崩溃
在 NSSplitView
中。如何以编程方式扩展和折叠NSSplitView的部分?
However, I'm missing RBSplitView
's handy methods expand
and collapse
in NSSplitView
. How can I expand and collapse parts of NSSplitView programmatically?
推荐答案
我只是通过编程方式扩展和折叠了 NSSplitView
运行。我还配置了 NSSplitView
,只要双击分隔线即可展开/折叠子视图,因此我希望此功能与该功能配合使用(看起来很不错) 。这就是我所做的:
I just got programmatic expanding and collapsing of NSSplitView
to work. I've also configured my NSSplitView
to expand/collapse a subview whenever the divider is double-clicked, so I wanted this to play nice with that feature (and it seems to). This is what I did:
(在此示例中, splitView
是 NSSplitView
本身, splitViewSubViewLeft
是我要扩展/折叠的子视图, lastSplitViewSubViewLeftWidth
是一个实例变量类型 CGFloat
。)
(in this example, splitView
is the NSSplitView
itself, splitViewSubViewLeft
is the subview I wish to expand/collapse and lastSplitViewSubViewLeftWidth
is an instance variable of type 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
];
}
这篇关于如何以编程方式扩展和折叠NSSplitView的各个部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!