查看当前view tree结构

来源:互联网 发布:阿里云com优惠口令 编辑:程序博客网 时间:2024/05/20 07:36
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
- (void)dumpView:(UIView *)aView atIndent:(int)indent into:(NSMutableString *)outstring  
{  
    for (int i = 0; i < indent; i++) [outstring appendString:@"--"];  
    [outstring appendFormat:@"[%2d] %@\n", indent, [[aView class] description]];  
    for (UIView *view in [aView subviews])  
        [self dumpView:view atIndent:indent + 1 into:outstring];  
}  
   
// Start the tree recursion at level 0 with the root view  
- (NSString *) displayViews: (UIView *) aView  
{  
    NSMutableString *outstring = [[NSMutableString alloc] init];  
    [self dumpView: self.window atIndent:0 into:outstring];  
    return outstring ;  
}  
// Show the tree  
- (void)logViewTreeForMainWindow  
{  
    //  CFShow([self displayViews: self.window]);  
    NSLog(@"The view tree:\n%@", [self displayViews:self.window]);  
}

执行结果例子:

转自:http://my.oschina.net/u/1418722/blog/232911

0 0
原创粉丝点击