本文代码最终实现界面为
两种方法可以实现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