NSSplitView 在垂直和水平布局之间切换时保存和恢复分割器位置
在我的应用程序中,我使用 NSSplitView,它能够使用 - (void)setVertical:(BOOL)flag
方法在垂直和水平布局之间切换。问题是,当用户更改布局时,分离器总是恢复其位置在 50%/50%。
NSSplitView 可以自动保存其分隔符,但它不会保存两种布局的值。
处理这个问题的最佳方法是什么?在每次调整大小和分割器移动时将子视图矩形保存在 NSUserDefault 中,并在布局切换时恢复它们?看起来不错吗?有没有更好的解决办法。
In my app I use NSSplitView which has ability to switch between vertical and horizontal layout using - (void)setVertical:(BOOL)flag
method. The problem is that when user change layout, splitter always restore its position on 50%/50%.
NSSplitView has an autosave possibility for its divider, but it doen't save values for both layouts.
What is the best way to handle this? Save subviews rects in NSUserDefault on every resize and splitter move and restore them when layout switched? Is it looks good? Is there a better solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,自动保存不适用于分割器位置(不知道为什么)。我最终完全按照您的建议进行了操作:将矩形保存在 NSUserDefaults 中。
此外,还有一个出色的 BWToolkit 及其分割视图,在分割位置方面应该可以正常工作。但请记住,我们的 IDE 版本 4(希望尚未)不支持插件;-)
Unfortunately, autosave doesn't work with splitter position (not sure why). I ended up doing exactly what you suggested: saving rects in NSUserDefaults.
Additionally, there is excellent BWToolkit with its Split View, which should work OK with regards to split position. Keep in mind though, that plugins are not (hopefully yet) supported in version 4 of our IDE ;-)