如何约束NSSplitView?
您好,我正在尝试限制 NSSplitView 的最大和最小坐标。我创建了一个视图控制器并将其指定为 NSSplitView 的委托。然而,委托方法被调用,分割视图并不限制我试图将其设置为的位置。关于我做错了什么有什么建议吗?
- (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 ;
}
Hi I'm trying to constrain the max and min coordinate of an NSSplitView. I've created a view controller and assigned it as the delegate of an NSSplitView. The delegate methods get called however, the split view does not constrain to the position that I am trying to set it as. Any suggestions as to what I am 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 ;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您希望垂直拆分器上的两个部分中的每一部分都至少为 70.0 高,那么您会执行以下操作:
进行减法的原因是动态考虑整体大小的任何调整(例如,使用自动布局) NSplitView 实例。如果您使用的是水平方向,则需要根据
.width
而不是.height
进行计算。如果您有 2 个以上的子视图,则可以通过查看dividerIndex 并应用您认为合适的值来扩展该想法。Let's assume you want each one of two sections on a vertical splitter to be at least 70.0 high, then what you'd do this:
The reason for the subtraction is to dynamically account for any resizing (with autolayout, for example) of the overall NSplitView instance. If you're working with a horizontal one, then you'd need to calculate against
.width
instead of.height
. If you have more than 2 subviews, the idea can be extended by looking at dividerIndex and applying values as you see fit.我通过这样做解决了这个问题。
I solved the problem by doing this.