您好我需要实现四个视图分割器,如Maya,3ds max,Blender或其他类似的建模工具。我在编辑器的Mac端使用NSSplitView,我需要知道用户何时拖动一个窗格来同步另一个窗格 有没有办法从一个NSSplitView获取新大小并同步另一个视图?我在这个编辑器的C#版本中有Windows Forms的代码,但我无法弄清楚如何在Mac上执行此操作。完整源代码位于http://github.com/filipkunc/opengl-editor-cocoa。
非常感谢。
答案 0 :(得分:4)
我用这段代码修复了它:
- (void)splitViewDidResizeSubviews:(NSNotification *)notification
{
NSSplitView *splitView = (NSSplitView *)[notification object];
NSView *topSubview0 = (NSView *)[[topSplit subviews] objectAtIndex:0];
NSView *topSubview1 = (NSView *)[[topSplit subviews] objectAtIndex:1];
NSView *bottomSubview0 = (NSView *)[[bottomSplit subviews] objectAtIndex:0];
NSView *bottomSubview1 = (NSView *)[[bottomSplit subviews] objectAtIndex:1];
if (fabsf([bottomSubview0 frame].size.width - [topSubview0 frame].size.width) >= 1.0f)
{
if (splitView == topSplit)
{
NSLog(@"topSplit");
[bottomSubview0 setFrame:[topSubview0 frame]];
[bottomSubview1 setFrame:[topSubview1 frame]];
}
else
{
NSLog(@"bottomSplit");
[topSubview0 setFrame:[bottomSubview0 frame]];
[topSubview1 setFrame:[bottomSubview1 frame]];
}
}
}