1

NSPopUpButton的文档指出:

NSPopUpButton 对象使用 NSPopUpButtonCell 对象来实现其用户界面。

我派生了一个新类,NSPopUpButtonCell从中实现drawBorderAndBackgroundWithFrame:inView:了自定义绘图。此外,我从中派生了一个新类,NSPopUpButton并用于cellClass使用我的派生类。(即我没有通过界面生成器工作。)

然而,随着 macOS 10.14 beta 的出现,不再调用此例程,我观察到“正常”(即非自定义)绘图。

感谢@Marc T.的回答,我(我想我)能够将问题定位为这样一个事实,即drawBorderAndBackgroundWithFrame:inView:只有drawInteriorWithFrame:inView:在派生单元中实现单元时才会调用该单元。

我找不到关于此的可靠文档。有没有?

4

1 回答 1

2

如果 macOS 10.14 有这样的变化,我认为 Apple 会在 WWDC 2018 上宣布这一点。快速检查 Interface Builder 告诉我,到目前为止没有任何变化。创建 NSPopUpButtonCell 的子类以将其用作弹出按钮单元的类仍然按预期工作。我必须提到的是,只有在实现 drawInterior 时才会调用 drawBorderAndBackground。由于我以前从未使用过 drawBorderAndBackground,因此我不能说这是否是从以前的版本到 10.14 的更改。

class Cell: NSPopUpButtonCell {

override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) {
    super.drawInterior(withFrame: cellFrame, in: controlView)
    print("drawInterior")
}

override func drawBorderAndBackground(withFrame cellFrame: NSRect, in controlView: NSView) {
    super.drawBorderAndBackground(withFrame: cellFrame, in: controlView)
    print("drawBorderAndBackground")
}
}

希望这可以帮助。

于 2018-07-05T05:58:40.937 回答