Re: Changing order of views dynamically
Re: Changing order of views dynamically
- Subject: Re: Changing order of views dynamically
- From: Andreas Mayer <email@hidden>
- Date: Tue, 20 Mar 2007 11:29:33 +0100
Am 20.03.2007 um 08:16 Uhr schrieb Sergey Shapovalov:
Yes, I get the point and I admit that what I was going to do has
been illegal.
It's not "illegal". It's just not guaranteed to work like you'd expect.
1. What is [NSView addSubview:positioned:relativeTo:] intended for
if relative positioning of overlapping subviews is not guaranteed
to work anyway?
I guess it's there because it'd make sense if ordering views worked
as you thought it did. While it does not at the moment, the API
designers added those methods for completeness' sake. You'll even
find methods in Cocoa that do absolutely nothing, for much the same
reasons.
But now I just want to understand how things work in Cocoa...
It's really simple: You read the documentation and act accordingly.
Or you don't and expect things to brake. :)
When the parent view draws itself, it also re-draws its subviews in
a loop. It calls drawRect for the subviews in the same order as the
subviews go in the array.
That's an implementation detail. Not only is it not documented, but
the documentation specifically says it might not always be true. So
you can't rely on it. (1)
Can anyone explain to me what is wrong with my approach?
Um. It's not guaranteed to work. Really, I don't know what else you
want to hear.
(1) OK, I'll make up a scenario in which your app might break:
Note that I'm *not* saying this is how thing work; they *might* work
this way. Or they might not. We just don't know.
1. Assume that all subviews are ordered from left to right, lowest to
topmost.
2. Assume view A < view B, i.e. B should be on top of A.
3. Assume view A.x+A.width > B.x, i.e. view B overlaps the rightmost
part of A.
4. Assume the control has to redraw a rectangle, X.
5. Assume X.x >= A.x, A.x < X.x+X.width < A.x+A.width, X.x+X.width >
B.x.
6. Now the superview might intersect each subviews rectangle with the
rectangle that is to be redrawn, find that A covers X completely and
therefore, as an optimization, stops the redraw loop after drawing A.
==> You have a redraw problem.
Andreas
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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