RE: Multiple Overlapping SubViews?
RE: Multiple Overlapping SubViews?
- Subject: RE: Multiple Overlapping SubViews?
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Mon, 15 Dec 2003 14:43:43 -0500
>
Is there a way for a window's content view to have multiple overlapping
>
subviews - i.e. subviews that occupy the same space?
Yes, that's exactly what you've done. Unfortunately, it sounds like one is
being drawn on top of the other. It sounds like maybe you want to composite
images. If so, check out NSImage.
>
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
>
adding each view as a subview of the window's contentView. Alas, only
>
the last view to be added as a subview in that rect is ever displayed.
>
That is, if I do:
>
>
[[myWindow contentView] addSubview:mySubView1];
>
[[myWindow contentView] addSubview:mySubView2];
>
>
then mySubView2 will be displayed, but not mySubview1. If I add
>
subView2 first, then only mySubView1 is displayed.
Not exactly. In all likelihood, the view is being displayed, and then the
second view is being displayed on top of it with an opaque background. If
the views did not draw their backgrounds, you'd probably be OK. NSTextView
has a -setDrawsBackground method. If you pass NO, drawing that is
"underneath" the text view is visible.
I seem to recall that you can get the same effect with:
[[NSColor clearColor] set];
NSRectFill([self bounds]);
in the view's drawRect: method. But I'm not sure about that. Worth a try?
Also, you cannot count on subviews being drawn in the order in which they
are added to a view.
>
>
The only workaround I've found is to create multiple separate
>
_windows_ for each
>
view, making each view a subview of its respective window. This is,
>
however, extremely cumbersome, and I can't imagine that it's the proper
>
way to do things.
This does sound strange. What effect are you trying to achieve, exactly?
Jonathan
_______________________________________________
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.