NSPopUpButton对象使用NSPopUpButtonCell对象实现其用户界面。
我从NSPopUpButtonCell派生了一个新的类,它实现了drawBorderAndBackgroundWithFrame:inView:来实现自定义绘图。此外,我从NSPopUpButton派生出一个新类,并使用cellClass为其使用派生类。(也就是说,我不是通过接口生成器工作的。)
然而,随着macOS 10.14测试版的出现,这个例程不再被调用,我观察到了“正常”(即非自定义的)绘图。
多亏了@Marc T.的答案,我(认为我)能够将问题定位到这样一个事实:只有在派生单元中实现drawInteriorWithFrame:inView:时,该单元显然才调用drawBorderAndBackgroundWithFrame:inView:。
我找不到这方面的可靠文件。有吗?
发布于 2018-07-05 05:58:40
如果macOS 10.14有这样的变化,我想苹果会在2018年WWDC上宣布这一点。在Interface中快速检查显示,到目前为止没有什么变化。创建一个NSPopUpButtonCell子类以将其用作弹出按钮单元格的类,仍按预期工作。我必须提到的是,只有当drawBorderAndBackground也被实现时,才会调用drawInterior。因为我以前从未使用过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")
}
}希望这能有所帮助。
https://stackoverflow.com/questions/51175125
复制相似问题