麻烦与NSSplitView开始尺寸(故事板和Swift) [英] Trouble With NSSplitView Starting Sizes (Storyboards and Swift)

查看:857
本文介绍了麻烦与NSSplitView开始尺寸(故事板和Swift)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始一个简单的Cocoa应用程序使用Swift,Storyboards和一个文档。

I just started a simple Cocoa app using Swift, Storyboards, and a Document.

我做的唯一的改变是替换默认的View Controller .storyboard与分割视图控制器。一切工作伟大的子视图填充正确,除了一件事:分隔线总是在窗口的最左边,当我启动应用程序。这是一个垂直分割视图。 (如果我改变为水平分隔线从顶部开始。)

The only change I've made is to replace the default View Controller in Main.storyboard with a Split View Controller. Everything works great as far as the subviews populating correctly except for one thing: the divider is always at the far left of the window when I start the app. This is with a vertical Split View. (If I change to horizontal the divider starts at the very top.)

我已经尝试添加约束,但是IB甚至不允许我添加约束到除了内容之外的任何东西

I have tried adding constraints but IB won't even allow me to add constraints to anything except content within the subviews.

我也尝试使用splitView.setPosition ofDividerAtIndex,但没有成功。

I've also tried using splitView.setPosition ofDividerAtIndex but had no success.

我可以指定左子视图的宽度或分隔符的位置?

How can I specify either the width of the left subview or the position of the divider?

推荐答案

分割视图的初始大小是基于约束。如果没有要满足的约束,则宽度或高度为0.您是正确的,您不能向根视图添加任何约束。您必须添加具有暗示所需高度或宽度的约束的子视图。

The initial size of the split view is based on the constraints. If there are no constraints to satisfy then the width or height is 0. You are correct, you can't add any constraints to the root view. You have to add subviews that have constraints that imply the desired height or width.

这可能只是一个具有设置宽度或高度约束的NSView。

This could simply be a NSView with a set width or height constraint.

这篇关于麻烦与NSSplitView开始尺寸(故事板和Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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