在开发 iOS 应用程序时,我发现在调试器中使用 po [[UIWindow keyWindow] recursiveDescription]
非常有用。但是,我想知道是否有一种工具可以优雅地表示输出以提高可读性?
最佳答案
这是我以前写的一个方法:
- (void)logView:(UIView*)v index:(int)i
{
NSMutableString *str = [NSMutableString string];
for (int u = 0; u<i; u++) { [str appendString:@"| "]; }
[str appendFormat:@"<%@ %p frame:%@>", v.class, v, NSStringFromCGRect(v.frame)];
// of course you can change it to display your accessibility hint/label
printf("%s\n", [str UTF8String]);
for (UIView *vv in v.subviews) { [self logView:vv index:i+1]; }
}
这样调用:[self logView:myView index:0];
示例输出:
<UITextField 0x6b30010 frame:{{20, 13}, {280, 31}}>
| <UITextFieldRoundedRectBackgroundView 0x6b31e00 frame:{{0, 0}, {280, 31}}>
| | <UIImageView 0x6b31fe0 frame:{{0, 0}, {0, 0}}>
| | <UIImageView 0x6b32070 frame:{{0, 0}, {0, 0}}>
| | <UIImageView 0x6b320e0 frame:{{0, 0}, {0, 0}}>
关于iphone - iOS 上 View 层级的可视化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11687519/