Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added -[TUIView ancestorSharedWithView:]

  • Loading branch information...
commit df38eb2ead833bec3335baeb7dad7761186ef40f 1 parent 395acea
@jspahrsummers jspahrsummers authored
Showing with 21 additions and 1 deletion.
  1. +6 −0 lib/UIKit/TUIView.h
  2. +15 −1 lib/UIKit/TUIView.m
View
6 lib/UIKit/TUIView.h
@@ -305,6 +305,12 @@ extern CGRect(^TUIViewCenteredLayout)(TUIView*);
- (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
*/
- (BOOL)isDescendantOfView:(TUIView *)view;
View
16 lib/UIKit/TUIView.m
@@ -723,7 +723,7 @@ - (void)setNextResponder:(NSResponder *)r
} 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 @@ - (void)didMoveToSuperview {}
#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;
Please sign in to comment.
Something went wrong with that request. Please try again.