• 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: How do you find an underlying view?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do you find an underlying view?


  • Subject: Re: How do you find an underlying view?
  • From: John Randolph <email@hidden>
  • Date: Thu, 12 Feb 2004 17:09:32 -0800

I don't have it on the machine in front of me, which means it's probably on a NeXT slab in my garage.

I wrote that on NeXTSTEP 3.3, and never even ported it over to OpenStep. If I were doing it today, I'd want to make it animate to the new configuration, etc.

-jcr


On Feb 12, 2004, at 11:50 AM, John Stiles wrote:

Is this collapsible box class available anywhere as sample code or something like that? We could *really* use it. I have some gnarly code right now that kind of does it, but it's pretty limited, and I'd love something more general-purpose.


On Feb 12, 2004, at 10:48 AM, John Randolph wrote:

On Feb 12, 2004, at 9:16 AM, email@hidden wrote:

Let's say that you have "topView" and "bottomView" that are both subviews of "mainView". The "topView" is placed above (using mainView.addSubview(topView, NSWindow.Above, bottomView) so that it covers "BottomView".

How can you programatically find what view is underneath "topView"? Is there a straightforward way of doing this or am I going to have to walk thru all the subviews of mainView and do my own overlapping tests? Anyone have code?

I needed to do something like this a few years back, when I was implementing a "collapsible box" class. When you collapsed the box, any sibling views below it would move up to fill the empty space, and the window would also get shortened.

The way I checked for a view being below another view was something like this:

@implementation NSView (layoutInfo)

- (BOOL) isAboveView:(NSView *) otherView { return [otherView isBelowView:self];}

- (BOOL) isBelowView:(NSView *) otherView
{
if ([otherView superview] == [self superview]) // are we sibling views?
{
NSRect myFrame = [self frame];
NSRect otherFrame = [otherView frame];
if (NSMinY(myFrame) < NSMinY(otherFrame)) // my frame is lower, check if I'm under the otherView
{
rect1.size.height = MAX_FLOAT; // extend height to infinity (in effect)
if (NSIntersectsRect(myFrame, otherFrame)
return YES;
}
}
return NO;
}

@end

In my earlier implementation, I also allowed for flipped coordinate spaces by translating the rects to the window's base coordinate system before testing.

-jcr
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >How do you find an underlying view? (From: email@hidden)
 >Re: How do you find an underlying view? (From: John Randolph <email@hidden>)
 >Re: How do you find an underlying view? (From: John Stiles <email@hidden>)

  • Prev by Date: Re: Spinning wait cursor in COCOA
  • Next by Date: Undo in NSTextView broken when runModalForWindow: ?
  • Previous by thread: Re: How do you find an underlying view?
  • Next by thread: Re: ERROR -- *** layout manager 12e71b0 reentrant glyph generation problem.
  • Index(es):
    • Date
    • Thread