【发布时间】:2020-07-21 06:04:40
【问题描述】:
我有一个包含两个按钮的 NSPopover。当我打开弹出框时,以下代码可以在将鼠标悬停在按钮上并单击按钮时将光标更改为指向手,控制台中会出现“按下按钮”,并且会根据需要显示 NSColorPanel。
class Button: NSButton {
override func resetCursorRects() {
super.resetCursorRects()
addCursorRect(bounds, cursor: .pointingHand)
}
}
@IBAction func buttonTapped(action:Any) {
print("Button pressed")
let cp = NSColorPanel.shared
cp.setTarget(self)
NSColorPanel.setPickerMode(.none)
cp.setAction(#selector(colorDidChange))
cp.isContinuous = false
cp.level = NSWindow.Level.statusBar
cp.makeKeyAndOrderFront(self)
}
但是,如果我单击屏幕上的任何其他位置,然后返回到 NSPopover,当鼠标悬停在按钮上时,指针不再出现,而 onClick 事件仍然被触发(如“按下按钮”所示登录控制台),NSColorPanel 没有打开。
关于为什么会出现这种情况的任何建议?
【问题讨论】:
-
我尝试了您的代码,但没有发现任何问题。请发帖minimal reproducible example。
标签: swift macos nsbutton nspopover nscolorpanel