Last active
August 29, 2015 14:05
-
-
Save SmallBlackCat/cca2c8284087539919a9 to your computer and use it in GitHub Desktop.
查看当前view tree结构
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Frome http://poolo.iteye.com/blog/1833821 | |
#import <UIKit/UIKit.h> | |
@interface UIView (Tree) | |
- (void)logViewTreeForMainWindow; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "UIView+Tree.h" | |
// Frome http://poolo.iteye.com/blog/1833821 | |
@implementation UIView (Tree) | |
- (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]); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment