| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 | - (void)viewDidLoad
{
    [super viewDidLoad];
    [self addViewToView:self.view];
    NSLog(@"%@", [self.view recursiveDescription]);
    NSLog(@"找到view: %@", [self.view viewWithTag:520]);
    NSLog(@"-----------------------");
    for (UIView *v in self.view.subviews) {
        [v removeFromSuperview];
    }
    [self addViewToView2:self.view];
    NSLog(@"%@", [self.view recursiveDescription]);
    NSLog(@"找到view: %@", [self.view viewWithTag:520]);
    NSLog(@"-----------------------");
    for (UIView *v in self.view.subviews) {
        [v removeFromSuperview];
    }
    [self addViewToView3:self.view];
    NSLog(@"%@", [self.view recursiveDescription]);
    NSLog(@"找到view: %@", [self.view viewWithTag:520]);
    NSLog(@"-----------------------");
    for (UIView *v in self.view.subviews) {
        [v removeFromSuperview];
    }
    [self addViewToView4:self.view];
    NSLog(@"%@", [self.view recursiveDescription]);
    NSLog(@"找到view: %@", [self.view viewWithTag:520]);
}
/* 递归添加520的view*/
- (void)addViewToView:(UIView *)view {
    static NSUInteger index = 0;
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [v setTag:520];
    [view addSubview:v];
    index++;
    if (index < 3)
        [self addViewToView:v];
}
/* 递归,每层增加两个view,第一个view为520tag,第二个为其他view
   往第一个view加子视图 
 */
- (void)addViewToView2:(UIView *)view {
    static NSUInteger index2 = 0;
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [v setTag:520];
    [view addSubview:v];
    UIView *v2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [view addSubview:v2];
    index2++;
    if (index2 < 3)
        [self addViewToView2:v];
}
/* 递归,每层增加两个view,第一个view为520tag,第二个为其他view
   往第二个view加子视图 
 */
- (void)addViewToView3:(UIView *)view {
    static NSUInteger index3 = 0;
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [v setTag:520];
    [view addSubview:v];
    UIView *v2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [view addSubview:v2];
    index3++;
    if (index3 < 3)
        [self addViewToView3:v2];
}
/* 递归,每层增加两个view,第一个为其他view,第二个view为520tag,
   往第一个view加子视图 
 */
- (void)addViewToView4:(UIView *)view {
    static NSUInteger index4 = 0;
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [view addSubview:v];
    UIView *v2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [v2 setTag:520];
    [view addSubview:v2];
    index4++;
    if (index4 < 3)
        [self addViewToView4:v];
}
 |