基于NSSplitViewController的应用程序几乎永远不会以正确的大小启动 [英] NSSplitViewController based application almost never launches with the correct size

查看:178
本文介绍了基于NSSplitViewController的应用程序几乎永远不会以正确的大小启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用NSSplitViewController作为根并连接了NSTabViewController作为其detailViewController的应用程序.

I have this app that uses a NSSplitViewController as the root and has a NSTabViewController connected as its detailViewController.

此应用设置为以1024x768启动.左窗格应以320x768启动,右窗格(tabViewController所在的位置)应以704x768启动.

This app is set to launch at 1024x768. The left pane should launch at 320x768 and the right pane (where the tabViewController is), should launch at 704x768.

从运行此应用程序的10次开始,将以不正确的大小(大约500x500)启动9次.另一个奇怪的事情是该应用程序不可扩展,但是如果将鼠标悬停在窗口边框附近,则会看到光标指示缩放.

From 10 times I run this app, 9 times it will launch with the incorrect size (about 500x500). Other strange thing is that this app should not be scalable, but if you hover the mouse near the window border you see cursor indication to scale.

我希望它以正确的大小启动,并且没有可扩展的选项.

I want this to launch at the correct size and have no scalable option.

这两个设置都在界面生成器上,但是被忽略了.

Both of these settings are on interface builder but are being ignored.

您可以在此处下载演示该问题的示例项目.停止并运行该项目几次以查看问题.

You can download a sample project that demonstrates the problem, here. Stop and run the project several times to see the problem.

我该如何解决?

推荐答案

我无法确定是什么导致了问题,但是解决问题的一种方法是添加一些约束. Interface Builder不允许您约束它插入到拆分视图左右面板中的默认NSView实例,因此您需要添加自己的实例.下面的屏幕截图 是从您的演示中获取的,但是在完成以下操作之后:

I couldn't say for sure what's causing the problem, but one way you may be able to solve it is to add some constraints. Interface Builder doesn't allow you to constrain the default NSView instances that it inserts into the left and right panels of the split view, so you'll need to add your own. The screen-shot below is taken from your demo, but after I've done the following:

  1. 在左侧拆分中添加了一个子视图(我的内容视图),并将其边缘固定在其父视图的边缘(视图Xcode自动将其添加到splitview)
  2. 我的内容视图
  3. 添加了明确的宽度限制(320像素)
  1. Added a subview to the left split (My Content View), and pinned it's edges to the edges of its superview (the view Xcode automatically adds to the splitview)
  2. Added an explicit width constraint of 320 pixels to My Content View

当我加载该应用程序时,两个拆分均可见,分隔线不退缩,并且窗口无法调整大小.

When I load the app both splits are visible, the divider doesn't budge, and the window can't be resized.

尽管约束是解决此问题的一种方法,但我认为问题的根源在于Interface Builder中的一些意外行为.当您将NSSplitViewController对象拖到画布上并使其成为窗口控制器的content window关系的目标时,实际上未设置拆分视图控制器的view出口.这样做的后果之一是,当您加载应用程序时,分隔线似乎就在一侧.要解决此问题,请将上述视图出口设置为指向拆分视图:

Although constraints are one way to solve this problem, I think the root of the problem lies in a bit of unexpected behaviour in Interface Builder. When you drag an NSSplitViewController object onto the canvas, and make it the target of the window controller's content window relationship, the split-view controller's view outlet is not actually set. One consequence of this appears to be that, when you load the app, the divider will appear to be right over to one side. To resolve this, set the aforementioned view outlet to point at the split view:

我创建了一个演示项目,其设置类似于提问者演示应用程序中的设置.

I've created a demo project with a setup similar to that in the questioner's demo app.

这篇关于基于NSSplitViewController的应用程序几乎永远不会以正确的大小启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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