比如有5个View, View1, View2, View3, View4.
view1的父view是View2, view2的父view是view3,view3的父view是view4
怎么判断view1是包含在view4里的?
view1.superView.superView.superView == view4 ?
但假如隔离几代是不知道的。我只想知道view1是否包含在某个view中,不管隔了几代,该怎么判断?
------解决方案--------------------
View *view = view1;
bool find = NO;
while (view != nil && !(find = (view.superView == view4)))
{
view = view.superView;
}
------解决方案--------------------
循环不错,也可以在当前view中加载你的父View;
[self.view addSubView: superView ];
------解决方案--------------------
- (BOOL)isDescendantOfView:(UIView *)view