无法启动 NSTrackingArea

Unable to start an NSTrackingArea

我有一个 NSOutlineView,我希望在拖放过程中进行 mouseEntered:mouseExited: 更新。所以我试着给它添加一个 NSTrackingArea 。在我的大纲视图子 class 中,我有:

let target = self.frame
let options = [NSTrackingAreaOptions.enabledDuringMouseDrag]
let area = NSTrackingArea(rect: target, options: options, owner: self, userInfo: nil)
self.addTrackingArea(area)

但是我好像得到了运行时异常:

[General] trackingArea options 0x400 do not include a type

这一定很明显,但所有 Google 结果似乎都没有表明我做错了什么。如果我这样做:

var trackingID = self.addTrackingRect(target, owner: self, userData: nil, assumeInside: false)

鼠标方法确实会触发,但显然只有在释放鼠标按钮时才会触发。

来自documentation

NSTrackingAreaOptions

The data type defined for the constants specified in the options parameter of init(rect:options:owner:userInfo:). These constants are described below; you can specify multiple constants by performing a bitwise-OR operation with them. In particular, you must supply one or more of the tracking-type constants (that is, mouseEnteredAndExited, mouseMoved, and cursorUpdate) and one of the active constants (that is, activeWhenFirstResponder, activeInKeyWindow, activeInActiveApp, and activeAlways). In addition, you may specify any of the behavior constants (that is, assumeInside, inVisibleRect, and enabledDuringMouseDrag).

这意味着需要一个或多个 type 常量和一个 active 常量。