// 遍历 UIView 的所有子视图
for (UIView *subView in self.view.subviews) {
NSLog(@"%@",subView);
}
// 或者
for (int i=0; self.view.subviews.count; i++) {
NSLog(@"%@",self.view.subviews[i]);
}
[self TraverseAllSubviews:self.view];
//遍历父视图的所有子视图,包括嵌套的子视图
-(void)TraverseAllSubviews:(UIView *)view {
for (UIView *subView in view.subviews) {
if (subView.subviews.count) {
[self TraverseAllSubviews:subView];
}
NSLog(@"%@",subView);
}
}
// 获取子视图父控制器和父视图
UIView *next=self.view;
while ([next superview]) {
next=[next superview];
UIResponder *nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]&&![nextResponder isKindOfClass:[UINavigationController class]]) {
Class cls=[nextResponder class];
NSLog(@"ClassName:%@",cls);
}
NSLog(@"%@",next);
NSLog(@"",nextResponder);
}
// 或者
for (UIView *next = [self.view superview]; next; next = next.superview) {
NSLog(@"UIView---%@",next);
if ([next isKindOfClass:[Swiper class]] && next.tag==88) {
// TODO
}
UIResponder *nextResponder = [next nextResponder];
NSLog(@"UIResponder---%@",nextResponder);
}