NSToolbar 在 Leopard 和 Snow Leopard 中看起来不同
我正在开发一个 Cocoa 应用程序,并且 NSToolbar 我用于主窗口。
具体来说,我使用搜索字段作为最后一个 NSToolbarItem 并且,在 Snow Leopard 下它可以正确显示:
它是在 Leopard 下剪切的:
看看这两个版本,我在项目之间放置的空格在 Leopard 下似乎不受尊重。我还发现,有时,在 Interface Builder 的工具栏上进行一些更新后,即使在 Snow 下,这些更改也不会反映在正在运行的应用程序中。我必须从自定义菜单中拖动默认栏才能看到它们。
更新 NSToolbar 并不总是镜像 .nib 文件中的内容的原因在于为我启用的自动保存机制,正如 NSGod 所建议的那样。
造成这种不当行为的原因是什么? 我应该考虑一些关于约束(最小和最大)尺寸的事情吗? 请随时向我提供一些文档
更新 2 有没有办法以编程方式将项目和空间引入 NSToolbar 或检查使用 Interface Builder 输入的项目和空间的一致性(在运行时)?
I have a Cocoa app I'm working on and I get a different result in appearance for the NSToolbar I am using for the main window.
Specifically, I'm using a search field as the last NSToolbarItem and, whereas under Snow Leopard it is displayed correctly:
it is cut under Leopard:
Looking at those two versions it appears that the spaces I put between the items are not respected under Leopard. I also saw that sometimes, after I make some update at the toolbar in Interface Builder, these changes are not mirrored in the running application even under Snow. I have to drag the default bar from the customizing menu in order to see them.
UPDATE
The reason for the NSToolbar not always mirroring what is in the .nib file resides in the autosave mechanism that was enabled for me, as NSGod suggested.
What can be the cause of this misbehavior?
Is there something about constraints, (minimum and maximum) sizes that I should have taken into account?
Feel free to point some documentation to me
UPDATE 2
Is there a way to programmatically introduce item and spaces into a NSToolbar or check the consistency (at run time) of those entered with Interface Builder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我确实记得 NSToolbar 中的搜索字段有一些奇怪的地方,但我从未见过右侧被切断的行为。
作为空间的 NSToolbarItem 是固定单位空间还是灵活空间?
您需要记住,如果您在工具栏中启用了用户自定义和自动保存行为,那么当用户明确进行更改时,它将保存到用户默认值。如果您然后在 IB 中重新排列工具栏并运行应用程序,用户默认值中保存的配置可能会覆盖您在 nib 文件中指定的默认配置,
我通常做的是在测试期间删除应用程序的首选项文件 。所以更改不能被覆盖。(FWIW,我通常使用保存在 Dock 中的 AppleScript。它只运行一个
do shell script
命令来删除首选项文件。对于面向 GUI 的人来说,在调试之前只需单击它即可运行它会更容易,此版本的脚本要求删除 prefs 文件,尽管它也可以自定义:http://www.markdouma.com/developer/DeleteAppPrefs.zip。如果您以前从未运行过它,则会出现选择文件对话框,并且所选文件将作为别名保存在实际的 AppleScript 中,因此不会再次询问您。您可以将图标拖到 AppleScript 编辑器上以查看脚本或更改它)。无论如何,如果我要发布使用新工具栏布局的应用程序的新版本,并且想要防止配置被覆盖,我会将工具栏的标识符(或自动保存名称)更改为类似“ docToolbar2.0”。
While I do recall having a couple of oddities with search fields in
NSToolbar
s, I've never seen the behavior where the right side of it is cut off.Are the
NSToolbarItem
s that are spaces the fixed one-unit space, or the flexible spaces?You need to keep in mind that if you've enabled user customization and autosave behavior in the toolbar, then when the user explicitly makes a change, it will be saved to user defaults. If you then re-arrange your toolbar in IB and run the app, it's possible that the configuration saved in user defaults is overriding the default configuration you've specified in the nib file.
What I usually do is during testing, delete the prefs file for my app so changes can't be overridden. (FWIW, I usually use an AppleScript saved as an application that I keep in my Dock. It just runs a
do shell script
command which deletes the prefs file. Being a GUI-oriented type of person, it's easier for me to just click it to have it run right before debugging. This version of the script asks for the prefs file to delete, though it can also be customized: http://www.markdouma.com/developer/DeleteAppPrefs.zip. If you've never run it before, you get the choose file dialog, and the chosen file is saved as an alias inside the actual AppleScript, so you're not asked again. You can drag the icon onto AppleScript Editor to take a look at the script or change it).Anyway, then, if I'm going to release a new version of an app that uses a new toolbar layout, and want to prevent the config from being overridden, I'll change the toolbar's identifier (or autosave name) to something like "docToolbar2.0".