Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to start an NSTrackingArea

I have an NSOutlineView that I'd ike to have mouseEntered: and mouseExited: updates during drag and drop. So I've tried to add an NSTrackingArea to it. Within my outline view sub-class I have:

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

But I seem to get the runtime exception:

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

It must be something really obvious but all the Google results don't seem to indicate what I'm doing wrong. If I do:

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

then the mouse methods do fire but obviously only when the mouse button is released.

like image 794
Todd Avatar asked Mar 13 '17 18:03

Todd


1 Answers

From the 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).

That means one or more of the type constants and one of the active constants are required.

like image 67
vadian Avatar answered Nov 07 '22 15:11

vadian