Unable to start an NSTrackingArea
Asked Answered
W

1

5

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.

Weatherman answered 13/3, 2017 at 18:17 Comment(0)
I
9

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.

Ithaca answered 13/3, 2017 at 18:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.