Re: How do you find an underlying view?
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 10:48:41 -0800
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.