Re: Are views active or inactive?
Re: Are views active or inactive?
- Subject: Re: Are views active or inactive?
- From: Joar Wingfors <email@hidden>
- Date: Tue, 22 Dec 2009 21:58:51 -0800
On 22 dec 2009, at 19.45, Rick Mann wrote:
>>> Do NSViews have the notion of being "active" or "inactive?" My app architecture requires that I be able to differentiate, at draw time, between a (custom) view that is in the frontmost window (and technically, has focus), and a similar custom view that is in a non-frontmost window.
>>
>> Listen for NSWindowDidBecomeMainNotification. -viewDidMoveToWindow is
>> a good time to start, and -viewWillMoveToWindow: is a good time to
>> stop.
>
> I'm listening for that notification. Sure is a clunky way to do things. I've never used a view framework that didn't tell views when they became active/inactive.
Lot's of interesting advice in this thread... :-)
You don't have to listen to any notifications to achieve this. You will be asked to draw when the state of the window changes, and when you become or resign first responder status.
So, you don't have to figure out *when* to draw, but you do have to figure out *how* to draw.
Here are two things that you're often interested in taking into account:
* Is your window the key window
([NSApp keyWindow] == [self window])
* Are you the first responder of that window
([[self window] firstResponder] == self)
You can of course also track the state of these "properties" at all times using notifications and overrides of methods from your superclasses, but there is - like I said earlier - in general no need to.
j o a r
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden