Re: Multiple Overlapping SubViews?
Re: Multiple Overlapping SubViews?
- Subject: Re: Multiple Overlapping SubViews?
- From: Jon Hull <email@hidden>
- Date: Tue, 16 Dec 2003 00:37:22 -0800
On Dec 15, 2003, at 9:56 AM, John Rieffel wrote:
>
Is there a way for a window's content view to have multiple overlapping
>
subviews - i.e. subviews that occupy the same space?
>
>
I've tried to do this by creating two NSView instances with the same
>
frame (calling initWithFrame: with the same NSRect for each), and then
>
[]
Unfortunately, I believe that the behavior of overlapping sibling views
is undefined. The easiest remedy is to draw everything in one view.
If you want to have different layers of the drawing in different
objects (so you can turn them on and off individually, add new layers
via plugins, etc), then you need to take a page from NSCell.
Basically for each type of layer, you create a lightweight class that
knows how to draw itself, and has accessor methods for any data which
the object needs to draw itself (e.g. your sound data). Your NSView
subclass should have an array of these layer objects, and methods for
adding/removing layers from the array. All your view's drawRect:
method needs to do is tell each layer object in the array to draw. The
one caveat to this design is that the layer objects must make sure that
they leave the drawing state exactly as they found it (or the other
layers may draw incorrectly). The upside is that this is much more
efficient than having several views, and that the view is extremely
reusable.
For more info read the docs on how and why NSControl and NSCell are
related.
Hope it helps!
Thanks,
Jon
_______________________________________________
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.