//UIView的方法
//- (nullable __kindof UIView *)viewWithTag:(NSInteger)tag; // recursive search. includes self
// Decelerate : 减速
// Accelerate : 加速
// asc : 升序 1,2,3,4,5,6
// desc : 降序 6,5,4,3,2,1
//递归遍历寻找合适的子控件
@implementation UIView
- (UIView *)viewWithTag:(NSInteger)tag
{
// 如果自己的tag符合要求, 就返回自己
if (self.tag == tag) return self;
// 遍历子控件,查找tag符合要求的子控件
for (UIView *subview in self.subviews) {
// if (subview.tag == tag) return subview;
UIView *resultView = [subview viewWithTag:tag];
if (resultView) return resultView;
}
// 找不到符合要求的子控件
return nil;
}
@end
网友评论