NSToolbarItem: “Make sure this toolbar item has a valid frame/min/max size”?

只愿长相守 提交于 2019-12-05 19:16:25

问题


Since upgrading to Mac OS Sierra and the new XCode version I get the following error every time I launch my application for every one of the 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

I tried messing around in StoryBoard changing the size with no luck, when I searched around I found a couple of people having this issue as well with the new OS but no helpful answers.

Anyone facing the same issue, any advice?

Thanks a lot,

Marc


回答1:


Was not able to solve this in interface builder. However overriding minSize in subclass of NSToolbarItem solved the issue.

- (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];
    }
}



回答2:


For me, changing the maximum size of the NSToolbaritem as mentioned above did not work. But changing the minimum size of it did the trick. Warning message is now gone.




回答3:


I actually wasted much more time that I should have on this issue, but getting rid of warnings is one of my things. For me, no matter what I changed the toolbar button min/max sizes to, it complained about the sizes being incorrect by one or two pixels. I accidentally stumbled on the following workaround. My buttons use the 'Regular' control size. In IB, I changed each NSButton from Regular to Small, Small to Mini, and then Mini back to Regular. I then adjusted the minimum height of each NSToolbarItem upward to be two less than the maximum. I'm not sure what really happened in the process. There may be a simpler solution, but I have now committed my storyboard and I'm still holding my breath that the warnings don't come back!




回答4:


Originally I tried this (see update below thought):

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

Summarizing:

My options are:

  • Change the max size as above, and have toolbar items potentially appear the wrong size pre-Sierra;

  • Ignore the warning and have everything appear as it should in each version;

Also note that:

I thought I'd already tried this without success, until I realized what was happening: I had edited the values, then closed the toolbar editor in IB. I've now realised that the changes were not being saved; when I reopened the toolbar editor, the old values were still showing. Running once with the toolbar editor open seems to have made the changes 'take". (And yes, I tried cleaning at various stages.)

UPDATE Dec 2016 -------

For some reason minSize was still changing randomly from time to time. In the end I've linked all of this NSToolBarItems to the following class, this has fixed it for me:

    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
        }
    }

}



回答5:


Found the problem! The problem is that in IB in Xcode, the minSize fields are bound only one-way to the XIB source. If you change the NSToolbarItem minSize in IB, it saves it appropriately. But if you reopen the panel, either by reopening Xcode, reopening the project or even just reopening the properties panel, it shows the default values again. So the properties panel at this point might show W 127 H 25 even though the source of XIB file (the XML) shows W 129 H 27 (whatever values you tried to set last time). So the minSize field values in Xcode IB's Properties panel aren't set correctly. This leads to the confusing situation that saving after reopening the Properties panel of the NSToolbarItem, your changes will be overwritten again. It's an Xcode bug it seems. @Marius' answer solves this runtime, the other solution is not to open the NSToolbarItem properties again after setting the minSize.



来源:https://stackoverflow.com/questions/39768476/nstoolbaritem-make-sure-this-toolbar-item-has-a-valid-frame-min-max-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!