Re: Notification when a view goes offscreen?
Re: Notification when a view goes offscreen?
- Subject: Re: Notification when a view goes offscreen?
- From: Troy Stephens <email@hidden>
- Date: Tue, 27 Jan 2004 11:31:40 -0800
On Jan 27, 2004, at 8:16 AM, Nicholas Francis wrote:
Hi guys...
In our app, I'm pulling complete view hierarchies off-screen, and
replacing them with something else. Is there a way for a view to get
notified when it goes offscreen (like in its parent being
-removeFromSuperview)?
NSView provides stub methods that get invoked when a view's window or
superview changes:
- (void)viewWillMoveToWindow:(NSWindow *)newWindow;
- (void)viewDidMoveToWindow;
- (void)viewWillMoveToSuperview:(NSView *)newSuperview;
- (void)viewDidMoveToSuperview;
You can override these in a subclass to receive notice of such
occurrences.
This covers views "going offscreen" in the way that I gather you are
concerned with here (due to swapping of views out of and into a window
via -removeFromSuperview and -addSubview: operations). If you were
interested in other ways that a view can "go offscreen" (e.g. due to
its window being closed or moved to another screen), you'd also want to
take a look at the notifications declared in NSWindow.h. For the
NSView -setHidden: API introduced in Panther, there is currently no
notification mechanism, but one could simply override -setHidden: to
invoke super's implementation and then perform whatever actions are
needed:
- (void)setHidden:(BOOL)hiding {
[super setHidden:hiding];
// Now do whatever we need to in response to this change...
}
Hope this helps.
Troy Stephens
Cocoa frameworks
_______________________________________________
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.