简体   繁体   English

NSSplitView和其超级视图之间的高度差-它来自哪里?

[英]Gap in height between NSSplitView and its superview - where is it coming from?

I am using Storyboards to build an OS X app. 我正在使用Storyboards构建OS X应用程序。 It is arranged such that my main window controller contains as its content view controller an NSSplitViewController. 它被安排为使我的主窗口控制器包含一个NSSplitViewController作为其内容视图控制器。

Sometimes, however, when I open up the app, there is a gap between the top of the split view and the bottom of the window's title bar: 但是,有时候,当我打开应用程序时,拆分视图的顶部与窗口标题栏的底部之间有一个缝隙:

有差距的应用

This gap goes away as soon as I resize the window. 调整窗口大小后,该缝隙就会消失。

I captured the view hierarchy and I saw these auto layout constraints. 我捕获了视图层次结构,并看到了这些自动布局约束。 One in particular looked interesting: 其中一个看起来特别有趣:

查看调试器

Interesting! 有趣! But I cannot find any place in my app that specifies these auto layout constraints, neither in the window nor the split view. 但是我在应用程序中找不到任何指定这些自动布局约束的位置,无论是在窗口还是在拆分视图中。

Once the window resizes, the constraint looks like this (this is on the NSThemeFrame): 窗口调整大小后,约束看起来像这样(在NSThemeFrame上):

在此处输入图片说明

The constraint isn't grayed out if I look at it from the NSSplitView: 如果从NSSplitView来看,约束不会变灰:

在此处输入图片说明

The difference of 22 makes some sense; 两者之差22是有道理的; that's the height of the title bar itself. 那就是标题栏本身的高度。

What can I do to find out what's making it behave like this? 我该怎么做才能弄清楚它的行为呢?

The issue ended up being that I needed to start from the inside out. 问题最终是我需要从内而外开始。 First, I checked the dimensions I specified on the frame for each of the views of the NSSplitView. 首先,我检查了在框架上为NSSplitView的每个视图指定的尺寸。 Once I got those dimensions, I then went to the NSSplitView's frame and set the dimensions accordingly. 一旦获得这些尺寸,就可以转到NSSplitView的框架并相应地设置尺寸。

Then, I went to the NSWindow's frame and ensured that its dimensions were at least as big as the dimensions of the NSSplitView. 然后,我转到NSWindow的框架,并确保其尺寸至少与NSSplitView的尺寸一样大。 If it's bigger, no problem, but if it's smaller, then the window opens up cut off. 如果它更大,那没问题,但是如果它更小,那么该窗口就会打开并被截断。

This may be just specific to my use case because I tried creating a new project and reproducing the issue, but wasn't able to reproduce it. 这可能只针对我的用例,因为我尝试创建一个新项目并重现该问题,但无法重现该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM