• 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: reordering of subviews ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reordering of subviews ?


  • Subject: Re: reordering of subviews ?
  • From: Andrew Platzer <email@hidden>
  • Date: Wed, 28 Nov 2001 12:56:11 -0800

On Wednesday, November 28, 2001, at 12:35 , Robert Miller wrote:
I have a view which contains some subviews that can be moved /
resized, etc., when I click on one of the subviews I want it to become
the frontmost subview overlaying the other subviews if needed. I tried
various ways to do this including this code where 'self' is the subview
inside of its mouseDown method..

[self retain];
[self removeFromSuperview];
[[self superview] addSubview:self];

the subview gets placed in an odd origin and i'm not sure if it is
really a subview again. it is not entirely visible, is there a way to
bring an NSView to the front of all other views ?

Not easily but then the reason for this is that you should never overlap views. You will get redraw and hit detection problems. Views should be nested only. Views are very big (> 140 bytes per instance), very heavyweight, and shouldn't be used for content objects (e.g. rectangles in a draw program.) Instead, have a single view that does drawing and hit detection in its content.

For example, you might have a view containing an array of 'items'. You draw method might be:

- (void)drawRect:(NSRect)rect
{
NSGraphicsContext* currentContext = [NSGraphicsContext currentContext]
;
int i, c = [items count];
for (i = 0; i < c; i++) {
MyObject obj = [items objectAtIndex:i];
NSRect frame = [obj frame];
if (NSIntersectsRect(frame, rect) {
[currentContext saveGraphicsState];
NSClipRect(frame);
[[[NSAffineTransform transform] translateXBy:NSMinX(frame) yBy:NSMinY(frame)] concat];
[obj draw];
[currentContext restoreGraphicsState];
}
}
}

and of course, do the for loop in reverse for hit testing.

Andrew
__________________________________________________________________
A n d r e w P l a t z e r
A p p l i c a t i o n F r a m e w o r k s
A p p l e


  • Follow-Ups:
    • Re: reordering of subviews ?
      • From: Gérard Iglesias <email@hidden>
References: 
 >reordering of subviews ? (From: Robert Miller <email@hidden>)

  • Prev by Date: reordering of subviews ?
  • Next by Date: Re: reordering of subviews ?
  • Previous by thread: reordering of subviews ?
  • Next by thread: Re: reordering of subviews ?
  • Index(es):
    • Date
    • Thread