Instance Method

addTrackingRect:owner:userData:assumeInside:

Establishes an area for tracking mouse-entered and mouse-exited events within the view and returns a tag that identifies the tracking rectangle.

Declaration

- (NSTrackingRectTag)addTrackingRect:(NSRect)rect owner:(id)owner userData:(void *)data assumeInside:(BOOL)flag;

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 mouseEntered: and mouseExited:.

userData

Data stored in the NSEvent object for each tracking event.

flag

If YES, the first event will be generated when the cursor leaves aRect, regardless if the cursor is inside aRect when the tracking rectangle is added. If NO the first event will be generated when the cursor leaves aRect if the cursor is initially inside aRect, or when the cursor enters aRect if the cursor is initially outside aRect. You usually want to set this flag to NO.

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 addCursorRect:cursor:. 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 addTrackingArea:).

See Also

Managing Tracking Rectangles

- removeTrackingRect:

Removes the tracking rectangle identified by a tag.