Re: re-ordering the layers of NSView's subviews
Re: re-ordering the layers of NSView's subviews
- Subject: Re: re-ordering the layers of NSView's subviews
- From: Dave Carpeneto <email@hidden>
- Date: Tue, 23 Mar 2010 20:48:43 -0400
Graham Cox wrote:
On 24/03/2010, at 11:30 AM, Dave Carpeneto wrote:
Hi all - I've got the following situation:
* A 'parent' NSView, which in turn has a number of subviews
* These subviews have been added via the [NSView addSubview:newView positioned:NSWindowAbove relativeTo:nil] method (so each time a user adds a subview it's @ the top of the viewing list)
* The subviews are not opaque, have layers, and sometimes overlap
My issue: when the user clicks on a subview I'd like that subview to become the 'top' subview, but I cannot see how this is possible (apart from deleting & re-adding the subview to the parent). Any ideas on how I can do this ?
FWIW, what I'm wanting is similar to overlapping icons in a finder window (click an exposed corner of an icon that covered by another icon & the icon clicked is magically brought to the top of the list).
This NSView method may help:
- (void)sortSubviewsUsingFunction:(NSComparisonResult (*)(id, id, void *))compare context:(void *)context
DAC> Thank you :-) ! Did not realize that the 'positioned' attribute
was simply a way to manipulate the order of the entries in the subviews
NSArray. This looks to be cool.
BUT BUT BUT BUT BUT...
Using views for what you're doing is not going to scale. Views are too heavyweight and you'll rapidly hit performance issues. In addition, views are not really designed for the task at hand here, and there is only limited support for overlapping sibling views.
DAC> Yeah, from what I can see everyone is recommending I do something
other than what I'm doing (it kinda looks like a lot of stuff regarding
overlapping subviews may be unsupported), however @ this point I haven't
seen any perf issues, and everything works fine (of course now that I've
said this 10.6.3 is gonna break everything I'm working on ;-) )
You should probably look to just using CALayers or rolling your own lightweight object that exists within a single view.
There are also ready-made 3rd party view subclasses out there that might do what you want if you need something like a Finder-like icon view.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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