以编程方式调整 NSSplitView 的大小
我曾经使用并喜欢 RBSplitView,但是我无法以编程方式重新实现它,因为某些版本的 xcode 不再支持 IB 插件。
因此我又重新使用 NSSplitView。 NSSplitView 可以满足我的需要,问题是 NSSplitView 的自动保存功能被破坏了。所以我决定自己实现。
我现在正在做的事情是调整 NSSplitView 的 1 个子视图的大小。
调整 NSSplitView 大小的正确方法是什么? - setPositionOfDivider:itIndex: 应该是可行的方法(还没有尝试过),但是我不知道如何获取分隔线的当前位置。
- 提前致谢
I used to use and love RBSplitView, however I failed at reimplementing it programmatically as a certain version of xcode does not support IB plugins anymore.
Therefore I went back to using NSSplitView. NSSplitView is fine for what I need, the thing is that the autoSave of NSSplitView is broken. So I decided to implement it myself.
The thing I am doing at the moment is resizing 1 of the subviews of the NSSplitView.
What is the proper way of resizing an NSSplitView? - setPositionOfDivider:itIndex: should be the way to go ( haven't tried it ), however I do not know how to get the current position of the divider.
-- thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我的经验,
NSSplitView
讨厌你并希望你受到伤害。RBSplitView
好多了,在我看来,编程布局的头痛是值得的(而且我已经被 ShortcutRecorder IB 插件烧焦了,我永远不会再回到 IB 插件了)。也就是说......
我知道确定分隔线当前位置的唯一方法是查看子视图,找到分隔线的视图,获取其框架,并计算出其位置,同时牢记分隔线厚度。您必须编写该代码是疯狂的,但该代码并不是那么困难,您可以将其放入一个类别中。
或者,如果您的需求变得复杂,请在还可以的时候返回到
RBSplitView
。In my experience,
NSSplitView
hates you and wishes you harm.RBSplitView
is so much better, it is worth IMO the headache of programatic layout (and I've been so burned with the ShortcutRecorder IB plugins that I will never go back to IB plugins).That said....
The only way that I know of to determine the current position of the divider is to look at the subviews, find the divider's view, take it's frame, and work out its position keeping in mind the
dividerThickness
. It is insane that you have to write that code, but the code isn't that incredibly difficult, and you can put it in a category.Or go back to
RBSplitView
while you still can, if your needs are ever going to be complicated.我在这里使用 Swift,但 Objective C 中应该存在相同的方法:
I'm using Swift here but the same method should exist in Objective C: