NSSplitView

本文代码最终实现界面为

两种方法可以实现divider的上下拖动:

1.调用NSSplitViewDelegate

/* Given a proposed position for one of the dividers of a split view, return a position at which the divider should be placed as the user drags it. If a split view has no delegate, or if its delegate does not respond to this message, the split view behaves as if it has a delegate that responds to this message by merely returning the proposed position. If a split view has a delegate, and the delegate responds to this message, it will be sent repeatedly as the user drags one of the split view‘s dividers.

*/

- (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex;

用此方法要先设置splitview的delegate为当前app([_splitOuter setDelegate:self];)或

- (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex

{

NSLog(@"split view is being dragged");

CGFloat position = proposedPosition;

return position;

}

2.调用通知

- (void) splitViewDidResizeSubviews:(NSNotification *)notification

//- (void) splitViewDidResizeSubviews:(NSNotification *)notification

//{

//

//    NSSplitView *split = [notification object];

//    NSString *splitName = [split identifier];

//

////    NSLog(@"split name is %@",[split identifier]);

//

//    NSArray *allviews = [split subviews];

//

//    if ([splitName isEqualToString:@"split_outer"]) {

//        //1.修改split_outer.topview中控件的大小位置

//        NSView *topView = [allviews objectAtIndex:0];

//        [[self.textViewConsole enclosingScrollView] setFrame:[topView frame]];

//

//        NSView *bottomView = [allviews objectAtIndex:2];

//        NSSize bottomSize = [bottomView frame].size;

//        NSRect bottomRect = {0,0,bottomSize.width,bottomSize.height};

//        [[self.tableViewProgress enclosingScrollView] setFrame:bottomRect];

//

//        //2.修改split_outer.bottomview中控件的大小位置

//        NSView *middleView = [allviews objectAtIndex:1];

//        NSRect middleRect = [middleView frame];

//

//        NSLog(@"x:%f,y:%f,w:%f,h:%f",middleRect.origin.x,middleRect.origin.y,middleRect.size.width,middleRect.size.height);

//

//        //3. 修改split_outer.middle下拉动时对应其它控件的大小

//        NSPoint point = NSMakePoint(0, 0);

//        [self.splitInner setFrameOrigin:point];

//        [self.splitInner setFrameSize:middleRect.size];

//

//        NSArray *innerSubViews = [self.splitInner subviews];

//

//        NSView *leftTableViewOuterView = [innerSubViews objectAtIndex:0];

//        NSSize leftTableViewOuterViewSize = [leftTableViewOuterView frame].size;

//        [[self.leftTableView enclosingScrollView] setFrameSize:leftTableViewOuterViewSize];

//        [[self.leftTableView enclosingScrollView] setFrameOrigin:point];

//

//        NSView *rightTableViewOuterView = [innerSubViews objectAtIndex:1];

//        NSSize rightTableViewOuterViewSize = [rightTableViewOuterView frame].size;

//        [[self.rightTableView enclosingScrollView] setFrameSize:rightTableViewOuterViewSize];

//        [[self.rightTableView enclosingScrollView] setFrameOrigin:point];

//

//    } else if([splitName isEqualToString:@"split_inner"]){

//        NSLog(@"xxxxxxx");

//

//         NSPoint point = NSMakePoint(0, 0);

//        NSArray *innerSubViews = [self.splitInner subviews];

//

//        NSView *leftTableViewOuterView = [innerSubViews objectAtIndex:0];

//        NSSize leftTableViewOuterViewSize = [leftTableViewOuterView frame].size;

//        [[self.leftTableView enclosingScrollView] setFrameSize:leftTableViewOuterViewSize];

//        [[self.leftTableView enclosingScrollView] setFrameOrigin:point];

//

//        NSView *rightTableViewOuterView = [innerSubViews objectAtIndex:1];

//        NSSize rightTableViewOuterViewSize = [rightTableViewOuterView frame].size;

//        [[self.rightTableView enclosingScrollView] setFrameSize:rightTableViewOuterViewSize];

//        [[self.rightTableView enclosingScrollView] setFrameOrigin:point];

//

//    }

//}

最后设置size inspector

每个view都要设置

http://i.cnblogs.com/Files.aspx

时间: 2024-10-28 14:25:40

NSSplitView的相关文章

SourceTree commit information window消失解决办法

https://answers.atlassian.com/questions/15282793/sourcetree-how-to-show-commit-information-panel 执行命令: defaults delete com.torusknot.SourceTreeNotMAS "NSSplitView Subview Frames repowindow_LogViewDescSplitter" 重启sourceTree

Mac 开发快速查阅目录

以下内容转自 <Leopard轻松编程:帮你节省代码> 目录: - Core Animation 核心动画 - 视图描绘 - 和快速查看协同工作 - 管理多视图(针对自定义的分页控件等) - 图片或者视图以iPhoto形式的动画表格进行呈现 - 设置你自己的智能组.播放列表.目录 - 在菜单里加入自定义视图 - 菜单增强 - 打印界面 - 全局类型标志 - 像邮件程序一样使用分栏视图 - 将文档图标显示在标题条内 - 类似iPhoto工具条形式的HUD窗口 - 控制窗口的材质.金属形式,并可以