NSSplitView 子视图大小以编程方式限制为容器 NSSplitView 的大小

发布于 2024-10-14 04:50:03 字数 918 浏览 3 评论 0原文

很难用语言来表达这个问题,但一个现实世界的例子会有所帮助。如果您查看 iTunes 应用程序,它似乎有一个 Sidebar | NSSplitView。内容拆分,以及用于源列表和图稿面板的嵌套NSSplitView

在此处输入图像描述 ======> 在此处输入图像描述

当您拖动分隔线以使侧边栏变薄时,图稿视图(内部 < 的下半部分) code>NSSplitView) 缩短以保持正确的纵横比。这就是我所追求的行为。

我已连接外部 NSSplitViewdelegate 来指向 sideBarController,这样我就可以获取大小更改并以编程方式调整分割视图下部的大小。 我有这一半的问题正常工作,也就是说,当我更改侧边栏宽度时,侧边栏面板会相应地调整其大小。

我在攻击中遇到的问题是当嵌套的 NSSplitView 的高度发生变化时如何调整侧边栏的宽度。我最初试图找到使内部 splitview 的分隔线不可拖动的方法,但找不到任何方法来做到这一点。我现在设置的方法是将内部滚动视图的委托设置为拥有主 splitview 的 windowController,然后计算高度以更改信息面板的宽度。

当然,改变一个分割视图的大小会导致另一个分割视图改变其大小,这会再次改变原始大小并创建无限循环。我可以添加标志和计时器来尝试解决这个问题,但看起来我已经在反其道而行之以实现此功能了。

如何正确地将嵌套分割视图面板限制为其父级宽度或更一般地说,复制 iTunes“所选项目/正在播放”视图的调整大小行为的最佳方法是什么?

It is hard to put this problem into words, but a real world example will help. If you look at the iTunes app, it appears to have a NSSplitView for the Sidebar | Content split, and a nested NSSplitView for the source list and artwork panel.

enter image description here ======> enter image description here

When you drag the divider to make the sidebar thinner, the artwork view (the bottom half of the inner NSSplitView) shortens to maintain the right aspect ratio. This is the behavior I am after.

I have hooked up the outer NSSplitView's delegate to point to the sideBarController so I can get the sizing changes and resize the lower portion of the split view programatically. I have this half of the problem working correctly, that is, when I change the sidebars, width, the sidebar panels adjust their size accordingly.

The problem I am having issues in attacking is how to resize the sidebar width when the nested NSSplitView's height is altered. I originally tried to find ways to make this inner splitview's divider non-draggable, but could not find any way to do that. The way I have it setup now is to set the inner scrollview's delegate to be the windowController that owns the main splitview, then do a calculation on the height to alter the width of the info panel.

Of course, altering ones size causes the other splitview to alter its size, which aters the originals size again and a endless loop is created. I could add flags and timers to try and work this out, but already it seems like I am going agains the grain here to achieve this functionality.

How can I properly constrain the nested splitview panel to its parents width or more generally, What is the best way to duplicate the resizing behaviors of the iTunes "Selected Item / Now Playing" view?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

白云悠悠 2024-10-21 04:50:03

您可以尝试查看我的 CHLayoutManager,这将允许您执行以下操作:

[mySplitView setLayoutName:@"splitview"];
CHLayoutConstraint *constraint = [CHLayoutConstraint constraintWithAttribute: CHLayoutConstraintAttributeHeight relativeTo:@"splitview" attribute: CHLayoutConstraintAttributeWidth];
[mySplitView addConstraint:constraint];

现在,每当您的 mySplitView 调整大小时,它会自动更新视图的高度以匹配宽度。

您可能需要根据您的情况做一些更复杂的事情,但这是总体思路。

You might try taking a look at my CHLayoutManager, which would allow you to do:

[mySplitView setLayoutName:@"splitview"];
CHLayoutConstraint *constraint = [CHLayoutConstraint constraintWithAttribute: CHLayoutConstraintAttributeHeight relativeTo:@"splitview" attribute: CHLayoutConstraintAttributeWidth];
[mySplitView addConstraint:constraint];

Now whenever your mySplitView resizes, it will automatically update the height of the view to match the width.

You may have to do something a bit more complex for your situation, but this is the general idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文