• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Subview Ordering
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subview Ordering


  • Subject: Re: Subview Ordering
  • From: Sean Murphy <email@hidden>
  • Date: Thu, 3 Aug 2006 22:30:45 -0400

On Aug 3, 2006, at 7:58 PM, Drarok Ithaqua wrote:

I've had a look in the archives and the docs, but I seem to only find one answer which seems a little convoluted.

I want to bring a view to the front of my window, like in IB (Layout -> Bring To Front / Send To Back), but the only
way I can find is
- (void)sortSubviewsUsingFunction:(int (*)(id, id, void *))compare context:(void *)context


I've tried
- (void)replaceSubview:(NSView *)oldView with:(NSView *)newView

in case that worked, but nothing happens.



I can achieve the functionality I want by using IB to put the view in front, and setting it as hidden,

but that's very inconvenient if I need to access the objects behind it.

Hi Drarok,

The AppKit does not support the layering of sibling views. The only *guaranteed* way to overlap views is to formally implement a view hierarchy and create subviews as necessary.

From the ADC:
"For performance reasons, Cocoa 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/ CocoaViewsGuide/WorkingWithAViewHierarchy/chapter_4_section_5.html>


I've come across times in which views almost have to be layered on top of each other. Consider the "Group-Box with Pop-Up Menu" technique as described in the HIG <http://developer.apple.com/ documentation/UserExperience/Conceptual/OSXHIGuidelines/XHIGLayout/ chapter_19_section_5.html>. It doesn't make much sense to have either one be an explicit subview of the other. I believe Carbon has a native control for this, but in Cocoa we must use an NSBox with a NSPopupButton overlapping the top of the box. How does everyone else accomplish this?

Also worth noting, overlapping views can result in very inconsistent behavior. As a demonstration, create an empty nib with one window and one nsview, each as a top-level object instantiated in the nib. Add two controls to each instance, and overlap them, and test the interface within IB. The window's controls overlap and will appear exactly as it does in authoring mode. The custom nsview's controls reverse their order during test mode and the front/back setting seems to be reversed from how it was set during authoring mode.

Given all of this, I try to avoid overlapping sibling views.

Hope that helps..
-Sean
_______________________________________________
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


References: 
 >Subview Ordering (From: Drarok Ithaqua <email@hidden>)

  • Prev by Date: Re: looks like Intel vs. PowerPC difference
  • Next by Date: Re: Distributed Objects and Control Tracking
  • Previous by thread: Subview Ordering
  • Next by thread: Re: Subview Ordering
  • Index(es):
    • Date
    • Thread