Re: Tracking Rect Obtuseness
Re: Tracking Rect Obtuseness
- Subject: Re: Tracking Rect Obtuseness
- From: Greg Weston <email@hidden>
- Date: Sun, 18 May 2003 16:43:36 -0400
On Sunday, May 18, 2003, at 01:52 PM, Henry McGilton wrote:
I am using tracking rects on a view so I can get mouseEntered
and mouseExited messages to do highlighting. I have discovered
by trial and error (and error, and error . . .) that if I add
the tracking rect *before* I add the view to its superview,
the tracking doesn't work. If I add the tracking rect
*after* placing the view in its superview, then it works as
I expect.
Similarly, this means that I can not have the initWithFrame
method of the view itself add the tracking rect to itself at
init time, which to me seems like the most reasonable place
to do the work.
So, what is the story with tracking rects?
From the docs:
(See "Handling Tracking-Rectangle and Cursor-Update Events in Views" in
the NSView docs)
Tracking rectangles, though created and used by NSViews, are actually
maintained by NSWindows. Because of this, a tracking rectangle is a
static entity; it doesn't move or change its size when the NSView does.
If you use tracking rectangles, you should be sure to remove and
reestablish them any time you change the frame rectangle of the NSView
that contains them. If you're using a custom subclass of NSView, you
can override the frame- and bounds-setting methods to do this. You can
also register an observer for the NSViewFrameDidChangeNotification, and
have it reestablish the tracking rectangles on receiving the
notification.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.