问题
Quick question. How can I hide and then show all the objects in a NSWindow without doing something terribly tedious and complicated?
Kevin
回答1:
I may be late to this particular party, but how about this?
[[window contentView] setHidden:YES];
And conversely...
[[window contentView] setHidden:NO];
That's certainly less tedious and complicated. :D
回答2:
for(NSView* view in [[window contentView] subviews])
{
[view setHidden:YES];
}
回答3:
Assuming everything is a NSView:
//Hide views
for (NSView *view in [[myWindow contentView] subviews]) {
[view setHidden:YES];
}
//Show views
for (NSView *view in [[myWindow contentView] subviews]) {
[view setHidden:NO];
}
You will probably need to call a setNeedsDisplay somewhere.
EDITED Sorry, been working in Ruby all day. Edited to make it Objective C :)
Untested, but should get you started.
来源:https://stackoverflow.com/questions/6756277/hide-show-all-objects-in-a-nswindow-cocoa