调整嵌套 NSView 的大小

发布于 2024-09-18 12:28:36 字数 634 浏览 12 评论 0原文

为了对各种独特的视图进行分类,我有一个精心设计的设置:通过工具栏选择主要类别,然后在类别的 NSScrollView 中选择特定窗格。这看起来像:窗口 -> NSViewController 控制五个视图 ->控制 X 视图的每个视图的子 NSViewController ->每个视图都包含一个核心图。简而言之,几乎每条路径的末尾都有一个核心图 CPLayerHostingView 的嵌套 NSViewController。

在我回答我的问题之前,请随时指出这是一个糟糕的实现。就用户友好性而言,我认为这是有道理的,但是嵌套对象的数量让我想知道是否有更好的方法。

现在,假设我已经以最好的方式设计了它,问题本身:假设我选择了一个类别,然后选择了其中的一个子项,并且正在查看渲染的图表。如果调整窗口大小,我希望图表能够适当调整大小。在 Interface Builder 中,我已经完成了实现这一目标所需的一切:从 CPLayerHostingView 到主窗口中的 NSView 的所有内容都已设置为在所有方向上自动调整大小。尽管如此,如果我在运行时调整大小,图形将保持静止并且不会调整大小或移动。在具有零个或一个 NSView 层的设计中,这会更容易调试,但在这种情况下我没有想法。

我可以使用哪些技巧(编程式的或基于 IB 的)来确保 NSView 根据窗口大小调整很多很多级别?

In order to categorize a wide variety of unique views, I have an elaborate setup: main categories are selected via a toolbar, and then specific panes are selected in a category's NSScrollView. This looks like: window -> NSViewController controlling five views -> sub-NSViewController for each view controlling X views -> each view contains a core-plot graph. In short, nested NSViewControllers with a core-plot CPLayerHostingView at the end of nearly every path.

Before I even get to my question, feel free to point out that this is a poor implementation. In terms of user-friendliness, I think it makes sense, but the sheer number of nested objects makes me wonder if there's a better way.

Now then, assuming I've designed it the best possible way, the question itself: suppose I have selected a category and then a sub-item within, and am looking at a rendered graph. I desire the graph to resize appropriately if the window is resized. In Interface Builder I have done everything necessary to make this happen: everything from the CPLayerHostingView to the NSView in the main window have been set to autosize in all directions. Despite this, if I resize at runtime, the graph stays still and does not resize or move. In a design with zero or one NSView tiers this would be much simpler to debug, but I'm out of ideas in this scenario.

What tricks, programmatic or IB-based, can I use to make sure an NSView resizes according to a window resize many, many levels up?

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

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

发布评论

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

评论(1

深巷少女 2024-09-25 12:28:36

您不仅需要设置弹簧和支柱,还需要确保选中“自动调整子视图大小”。

Not only do you need to set the springs and struts, but you also need to make sure "Autoresizes Subviews" is checked.

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