按照一個樹遞歸查找
遞歸順序是 先序...
底層代碼:
/*
A
-D1 0
-E1 10
-E2 0
-D2 10
-F1 0
-F2 0
-D3 0
[A viewWithTag:10]; // 返回E1
*/
/*
@implementation UIView
- (UIView *)viewWithTag:(NSInteger)tag
{
// 如果自己的tag符合要求,就返回自己
if (self.tag == tag) return self;
// 遍歷子控件(也包括子控件的子控件...),直到找到符合條件的子控件為止
for (UIView *subview in self.subviews) {
UIView *resultView = [subview viewWithTag:tag];
if (resultView) return resultView;
}
return nil;
}
@end