Establishes an area for tracking mouse-entered and mouse-exited events within the view and returns a tag that identifies the tracking rectangle.
SDK
- macOS 10.0+
Framework
- App
Kit
Declaration
func addTrackingRect(_ rect: NSRect, owner: Any, userData data: Unsafe Mutable Raw Pointer?, assumeInside flag: Bool) -> NSView.Tracking Rect Tag
Parameters
aRect
A rectangle that defines a region of the view for tracking mouse-entered and mouse-exited events.
userObject
The object that gets sent the event messages. It can be the view itself or some other object (such as an NSCursor or a custom drawing tool object), as long as it responds to both
mouse
andEntered(with:) mouse
.Exited(with:) userData
Data stored in the
NSEvent
object for each tracking event.flag
If
true
, the first event will be generated when the cursor leavesa
, regardless if the cursor is insideRect a
when the tracking rectangle is added. IfRect false
the first event will be generated when the cursor leavesa
if the cursor is initially insideRect a
, or when the cursor entersRect a
if the cursor is initially outsideRect a
. You usually want to set this flag toRect false
.
Return Value
A tag that identifies the tracking rectangle. It is stored in the associated NSEvent
objects and can be used to remove the tracking rectangle.
Discussion
Tracking rectangles provide a general mechanism that can be used to trigger actions based on the cursor location (for example, a status bar or hint field that provides information on the item the cursor lies over). To simply change the cursor over a particular area, use add
. If you must use tracking rectangles to change the cursor, the NSCursor
class specification describes the additional methods that must be invoked to change cursors by using tracking rectangles.
In macOS 10.5 and later, tracking areas provide a greater range of functionality (see add
).