9

自从升级到 Mac OS Sierra 和新的 XCode 版本后,每次我为每个 NSToolbarItems 启动我的应用程序时都会收到以下错误:

Example 1:
2016-09-29 12:46:58.659879 AppTest[] NSToolbarItem (<NSToolbarItem: >) had to adjust the size of <NSPopUpButton: > from {130, 26} to the expected size of {132, 27}. Make sure that this toolbar item view has a valid frame/min/max size. This is an app bug, please do not file a bug against AppKit or NSToolbar! Break on _NSToolbarAdjustedBorderedControlSizeBreakpoint
Example 2:
2016-09-29 12:46:58.666074 AppTest[] NSToolbarItem (<NSToolbarItem: >) had to adjust the size of <NSButton: > from {60, 25} to the expected size of {62, 27}. Make sure that this toolbar item view has a valid frame/min/max size. This is an app bug, please do not file a bug against AppKit or NSToolbar! Break on _NSToolbarAdjustedBorderedControlSizeBreakpoint

我尝试在 StoryBoard 中随意更改大小,但没有运气,当我四处搜索时,我发现有几个人在使用新操作系统时也遇到了这个问题,但没有有用的答案。

有人遇到同样的问题,有什么建议吗?

非常感谢,

马克

4

5 回答 5

1

对我来说,如上所述更改 NSToolbaritem的最大大小不起作用。但是改变它的最小尺寸就可以了。警告信息现在消失了。

于 2016-11-04T08:16:42.613 回答
1

无法在界面生成器中解决此问题。然而,在 NSToolbarItem 的子类中覆盖 minSize 解决了这个问题。

- (NSSize)minSize
{
    if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_12) {
        /* Overriding this getter seems to be the only solution for runtime error logs like: NSToolbarItem (<APMRegularToolbarItem: 0x60e000039460>) had to adjust the size of <NSButton: 0x60f0001acce0> from {40, 25} to the expected size of {42, 27}. Make sure that this toolbar item view has a valid frame/min/max size. This is an app bug, please do not file a bug against AppKit or NSToolbar! Break on _NSToolbarAdjustedBorderedControlSizeBreakpoint
         */
        return NSMakeSize(42, 27);
    }
    else {
        return [super minSize];
    }
}
于 2016-12-19T10:53:18.377 回答
1

发现问题了!问题是在 Xcode 中的 IB 中,minSize 字段仅单向绑定到 XIB 源。如果您在 IB 中更改 NSToolbarItem minSize,它会适当地保存它。但是,如果您通过重新打开 Xcode、重新打开项目甚至只是重新打开属性面板来重新打开面板,它会再次显示默认值。因此,此时的属性面板可能会显示 W 127 H 25,即使 XIB 文件(XML)的源显示 W 129 H 27 (无论您上次尝试设置的任何值)。因此 Xcode IB 的属性面板中的 minSize 字段值设置不正确。这导致了重新打开 NSToolbarItem 的属性面板后保存的混乱情况,您的更改将再次被覆盖。这似乎是一个 Xcode 错误。@Marius 的回答解决了这个运行时问题,

于 2017-01-29T16:19:19.557 回答
0

最初我尝试过这个(请参阅下面的更新):

http://cocoa-dev.apple.narkive.com/iSLaiCLR/strange-toolbar-item-error

总结:

我的选择是:

  • 如上所述更改最大尺寸,并且工具栏项目可能会在 Sierra 之前出现错误的尺寸;

  • 忽略警告,让每个版本中的所有内容都按原样显示;

另请注意:

我以为我已经尝试过但没有成功,直到我意识到发生了什么:我编辑了值,然后关闭了 IB 中的工具栏编辑器。我现在意识到没有保存更改;当我重新打开工具栏编辑器时,旧值仍在显示。在打开工具栏编辑器的情况下运行一次似乎使更改“接受”。(是的,我尝试在各个阶段进行清理。)

2016 年 12 月更新 --------

由于某种原因 minSize 仍然不时随机变化。最后,我将所有这些 NSToolBarItems 链接到以下类,这为我修复了它:

    import Cocoa

    class ToolbarItemAvoidMinWarningIssue: NSToolbarItem {

    var widthT: CGFloat = 60
    var heightT: CGFloat = 27

    override var minSize: NSSize{
        get {
            return NSSize(width: widthT, height: heightT)
        }
        set {
            widthT = newValue.width
        }
    }

}
于 2016-09-29T11:12:26.353 回答
0

实际上,我在这个问题上浪费了更多时间,但摆脱警告是我的事情之一。对我来说,无论我将工具栏按钮的最小/最大尺寸更改为什么,它都会抱怨尺寸不正确一到两个像素。我不小心偶然发现了以下解决方法。我的按钮使用“常规”控件大小。在 IB 中,我将每个NSButton从 Regular 更改为 Small,Small 更改为 Mini,然后将 Mini 更改回 Regular。然后我将每个NSToolbarItem的最小高度向上调整为比最大值小两个。我不确定在这个过程中到底发生了什么。可能有一个更简单的解决方案,但我现在已经提交了我的故事板,我仍然屏住呼吸警告不会回来!

于 2016-12-03T22:07:15.180 回答