How to restrict NSSplitView?

Hi, I am trying to limit the maximum and minimum coordinates of an NSSplitView. I created a view controller and assigned it as an NSSplitView delegate. However, delegate methods are called, the split view does not limit the position I'm trying to set. Any suggestions on what I'm doing wrong?
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex { NSLog(@"Constrain min"); if (proposedMinimumPosition < 75) { proposedMinimumPosition = 75; } return proposedMinimumPosition; } - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex { NSLog(@"Constrain max"); if (proposedMax > 200) { proposedMax = 200; } return proposedMax ; } 
+4
source share
2 answers

Suppose you want each of the two sections on a vertical splitter to be at least 70.0, so what would you do:

 - (CGFloat) splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex { return 70.0; } - (CGFloat) splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex { return splitView.frame.size.height - 70.0; } 

The reason for the subtraction is the dynamic accounting of any change in size (for example, autorun) of a common instance of NSplitView. If you work with horizontal, you will need to calculate instead of .width instead of .height . If you have more than two subzones, you can expand this idea by looking at dividerIndex and applying the values ​​as you like.

+1
source

I solved the problem by doing this.

 - (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview { return NO; } 
0
source

Source: https://habr.com/ru/post/1398344/


All Articles