Added -[TUIView ancestorSharedWithView:]

This commit is contained in:
Justin Spahr-Summers
2012-07-17 16:43:46 -07:00
parent 395acea816
commit df38eb2ead
2 changed files with 21 additions and 1 deletions
+6
View File
@@ -304,6 +304,12 @@ extern CGRect(^TUIViewCenteredLayout)(TUIView*);
- (void)willMoveToWindow:(TUINSWindow *)newWindow;
- (void)didMoveToWindow;
/**
* Returns the closest ancestor that is shared by the receiver and another view,
* or nil if there is no such view.
*/
- (TUIView *)ancestorSharedWithView:(TUIView *)view;
/**
Note: returns YES ff view == reciever
*/
+15 -1
View File
@@ -723,7 +723,7 @@ else CGContextSetRGBFillColor(context, 1, 0, 0, 0.3); CGContextFillRect(context,
} else {\
[self.subviews insertObject:view atIndex:index];\
}\
[view removeFromSuperview]; /* will call willAdd:nil and didAdd (nil) */ \
[view removeFromSuperview]; /* will call willAdd:nil and didAdd (nil) */ \
[view willMoveToSuperview:self]; \
view.nsView = _nsView;
@@ -835,6 +835,20 @@ else CGContextSetRGBFillColor(context, 1, 0, 0, 0.3); CGContextFillRect(context,
#define END_EACH_SUBVIEW }
- (TUIView *)ancestorSharedWithView:(TUIView *)view
{
TUIView *parentView = self;
do {
if ([view isDescendantOfView:parentView])
return parentView;
parentView = parentView.superview;
} while (parentView);
return nil;
}
- (BOOL)isDescendantOfView:(TUIView *)view
{
TUIView *v = self;