使用自动布局,如何在不强制宽度NSSplitView为静态的情况下在NSSplitView中居中放置子视图? [英] Using autolayout, how can I center a subview in an NSSplitView without forcing the width NSSplitView to be static?

查看:231
本文介绍了使用自动布局,如何在不强制宽度NSSplitView为静态的情况下在NSSplitView中居中放置子视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个NSViews内容的NSSplitView.左侧的NSView具有2个约束-Equal WidthsEqual Heights.正确的NSView有一个简单的名称,例如NSTextField,它通过约束Center X AlignmentCenter Y Alighment居中.这就是我希望在调整窗口和/或NSSplitView分隔符的大小时会看到的样子:

I have an NSSplitView with content in both NSViews. The left NSView has 2 constraints – Equal Widths and Equal Heights. The right NSView has something simple, say an NSTextField, which is centered via constraints Center X Alignment and Center Y Alighment. This is what I hoped it would look like as I resize the window and/or the NSSplitView divider:

正在发生的事情:

我尝试了很多配置更改,我尝试使用NSSplitViewController,而不是将NSSplitView放到NSViewController中以通过编程方式调整更多参数,但是我没有任何运气.每当调整窗口大小时,左视图始终会占据多余的空间.分隔符也会发生相同的情况(可以调整其大小,但是放开鼠标按钮会使分隔符向后捕捉).似乎我在这里缺少一些基本知识.

I've tried a great deal of configuration changes, I've tried using an NSSplitViewController vs just dropping an NSSplitView into an NSViewController to adjust more parameters programmatically, but I'm not having any luck. Whenever resizing the window, the left view always takes over the excess space. The same happens with the divider (it can be resized, but letting go of the mouse button causes it to snap right back). It seems there's something fundamental that I'm missing here.

推荐答案

文本字段的内容包含优先级可能高于拆分视图项目的保留优先级.修复该问题,该视图应该可以按您期望的方式工作.

The text field's content hugging priority is probably higher than the split view item's holding priority. Fix that and the view should probably work the way you expect.

此外,如果在调整视图大小时,左视图与窗口一起调整大小,而右视图保持相同大小,则表明左视图的保留优先级可能高于右视图.您应该使要保持相同尺寸的那一侧具有更高的固定优先级.

Also, if, when you resize the view, the left view is resizing with the window while the right view stays the same size, then that suggests that the left view's holding priority may be higher than the right's. You should make the side that you want to stay the same size have the higher holding priority.

也就是说,我不确定您对子视图设置的约束的含义. 左边的NSView有2个约束-Equal WidthsEqual Heights."你这是什么意思它的宽度等于什么?它的高度等于什么?您是说它具有宽高比约束吗?坦白说,我想不出哪种限制对于拆分视图中的视图有意义.

That said, I'm not sure what you mean about the constraints you've set on the subviews. "The left NSView has 2 constraints – Equal Widths and Equal Heights." What do you mean here? Its width is equal to what? Its height is equal to what? Do you mean it has an aspect ratio constraint? Frankly, I can't think of what constraints of those kinds would make sense for a view within a split view.

这篇关于使用自动布局,如何在不强制宽度NSSplitView为静态的情况下在NSSplitView中居中放置子视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆