Re: How to change the z-order of the NSView
Re: How to change the z-order of the NSView
- Subject: Re: How to change the z-order of the NSView
- From: Nicko van Someren <email@hidden>
- Date: Wed, 2 Feb 2005 12:16:16 +0000
On 2 Feb 2005, at 11:21, j o a r wrote:
On 2005-02-02, at 12.11, JanakiRam wrote:
I am having a view in which randomly more views will be added. When i
place a view on another view, the some part view frame is hidden by
the newly added view. When i click on the view which is back i should
bring the NSView to front i.e changing the z-order of the view.Please
help me in this regard.
There is no built-in behaviour to sort sibling (views sharing a
superview) views on z-order when clicked. The documentation also in
general advice against overlapping sibling views:
"For performance reasons, the Application Kit does not enforce
clipping among sibling views, or guarantee correct invalidation and
drawing behavior when sibling views overlap. If you want a view to be
drawn in front of another view, you should make the front view a
subview (or descendant) of the rear view."
<http://developer.apple.com/documentation/Cocoa/Conceptual/DrawViews/
Concepts/ViewHierarchy.html>
Of course if you had quoted the sentence before the one you did quote
it would have been useful, since it contains the answer to the question
in hand! It says: "You can add NSViews to and remove them from the
view hierarchy using the methods addSubview:, removeFromSuperview, and
replaceSubview:with:. An additional method,
addSubview:positioned:relativeTo:, allows you to specify the ordering
of NSViews."
As it goes on to say, the handling of the overlaps is such that you
should be very careful with redrawing and invalidation but the layering
does work as expected, e.g. views placed on top of other views are
drawn later and if the sub-views are opaque then then cover up what is
below. The issues come with the clipping and invalidation, not the
layering per se. The current implementation seems to perform little or
no clipping of what is drawn in the lower views based on the position
of the upper views which means that things can get slow if you have
lots of views being draw in a way which obscures the the views below.
Note also that NSView offers the sortSubviewsUsingFunction:context:
method which : "Orders the receiver immediate subviews using the
comparator function compare, which takes as arguments two subviews to
be ordered and the context supplied" This is handy if you want to
change the ordering of a bunch of views all at once (for instance I've
used this to reverse the order of a stack of views all in one go).
Nicko
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden