我一直在为OS X上传一个上传menubar应用程序的小图片.我NSView
为上传的项目创建了自定义子类.
这是默认情况下的样子:
鼠标事件由视图NSViewController
按以下方式处理:
import Cocoa class MenuItemController: NSViewController { private var trackingArea: NSTrackingArea? override func mouseEntered(theEvent: NSEvent) { if let v = self.view as? MenuItemView { v.shouldHighlight = true v.needsDisplay = true } } override func mouseExited(theEvent: NSEvent) { if let v = self.view as? MenuItemView { v.shouldHighlight = false v.needsDisplay = true } } override func viewDidLoad() { super.viewDidLoad() if (trackingArea == nil) { trackingArea = NSTrackingArea(rect: self.view.bounds, options: [.ActiveAlways, .MouseEnteredAndExited], owner: self, userInfo: nil) self.view.addTrackingArea(trackingArea!) } /* rest of the code... */ } }
它工作正常,直到我快速移动光标的项目.看起来mouseExited()
事件没有被调用,并且视图保持蓝色背景(鼠标实际上在Quit按钮上):
我也尝试将鼠标处理移动到NSView
,但结果相同.我感谢任何输入!谢谢!