一. 简述
拆分视图,在水平或垂直运行的线性堆栈中排列两个或多个视图的视图。
默认为水平方向
@interface NSSplitView : NSView
|
二. 官方属性方法
@property (nullable, weak) id<NSSplitViewDelegate> delegate;
- (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview; - (void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize; - (void)splitViewWillResizeSubviews:(NSNotification *)notification; - (void)splitViewDidResizeSubviews:(NSNotification *)notification; - (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview; - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex; - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex; - (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex;
@property BOOL arrangesAllSubviews API_AVAILABLE(macos(10.11)); @property (readonly, copy) NSArray<__kindof NSView *> *arrangedSubviews API_AVAILABLE(macos(10.11)); - (void)addArrangedSubview:(NSView *)view API_AVAILABLE(macos(10.11)); - (void)insertArrangedSubview:(NSView *)view atIndex:(NSInteger)index API_AVAILABLE(macos(10.11)); - (void)removeArrangedSubview:(NSView *)view API_AVAILABLE(macos(10.11)); - (void)adjustSubviews; - (BOOL)isSubviewCollapsed:(NSView *)subview; - (NSLayoutPriority)holdingPriorityForSubviewAtIndex:(NSInteger)subviewIndex API_AVAILABLE(macos(10.8)); - (void)setHoldingPriority:(NSLayoutPriority)priority forSubviewAtIndex:(NSInteger)subviewIndex API_AVAILABLE(macos(10.8)); @property (nullable, copy) NSSplitViewAutosaveName autosaveName API_AVAILABLE(macos(10.5));
@property (getter=isVertical) BOOL vertical; @property NSSplitViewDividerStyle dividerStyle API_AVAILABLE(macos(10.5)); typedef NS_ENUM(NSInteger, NSSplitViewDividerStyle) { NSSplitViewDividerStyleThick = 1, NSSplitViewDividerStyleThin = 2, NSSplitViewDividerStylePaneSplitter API_AVAILABLE(macos(10.6)) = 3, } API_AVAILABLE(macos(10.5)); @property (readonly, copy) NSColor *dividerColor API_AVAILABLE(macos(10.5)); @property (readonly) CGFloat dividerThickness; - (void)drawDividerInRect:(NSRect)rect;
- (CGFloat)minPossiblePositionOfDividerAtIndex:(NSInteger)dividerIndex API_AVAILABLE(macos(10.5)); - (CGFloat)maxPossiblePositionOfDividerAtIndex:(NSInteger)dividerIndex API_AVAILABLE(macos(10.5)); - (void)setPosition:(CGFloat)position ofDividerAtIndex:(NSInteger)dividerIndex API_AVAILABLE(macos(10.5));
|
三. 示例<代码>
使用代码创建NSSplitView
,想要用Storyboard
创建的自行研究,比较简单
- (NSSplitView *)splitView { if (!_splitView) { _splitView = [[NSSplitView alloc] initWithFrame:CGRectMake(10, 100, 600, 400)]; _splitView.delegate = self; _splitView.vertical = YES; _splitView.dividerStyle = NSSplitViewDividerStylePaneSplitter; _splitView.wantsLayer = YES; _splitView.layer.backgroundColor = NSColor.whiteColor.CGColor; _splitView.toolTip = @"代码创建SplitView"; } return _splitView; }
- (void)viewDidLoad { [super viewDidLoad]; self.view.wantsLayer = YES; self.view.layer.backgroundColor = NSColor.lightGrayColor.CGColor; [self addSplitView]; }
- (void)addSplitView { NSView *leftView = [[NSView alloc] initWithFrame:CGRectMake(0, 0, 100, 400)]; [self.splitView addArrangedSubview:leftView]; NSView *rightView = [[NSView alloc] initWithFrame:CGRectMake(100, 0, 500, 400)]; [self.splitView addArrangedSubview:rightView]; [self.view addSubview:self.splitView]; }
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex { return 100; }
- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex { return 200; }
- (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview { return YES; }
|