如何约束NSSplitView?

发布于 2025-01-08 16:16:35 字数 704 浏览 0 评论 0原文

您好,我正在尝试限制 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寒冷纷飞旳雪 2025-01-15 16:16:35

假设您希望垂直拆分器上的两个部分中的每一部分都至少为 70.0 高,那么您会执行以下操作:

- (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;
}

进行减法的原因是动态考虑整体大小的任何调整(例如,使用自动布局) 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:

- (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 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.

小忆控 2025-01-15 16:16:35

我通过这样做解决了这个问题。

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

I solved the problem by doing this.

- (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview 
{
    return NO;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文