iphone - iOS 上 View 层级的可视化

标签 iphone ios xcode ipad

在开发 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/

相关文章:

ios - 如何在 iPhone 应用程序中使用谷歌翻译 API V2?

c++ - freopen() 在 Mac 上不起作用

ios - 如何在 iOS 10 模拟器上运行在 Xcode 7.3.1 中编译的应用程序

ios - PowerShell [System.IO.StreamWriter] 写入控制台(Write-Host)?

ios - Angular 6 - IOS 中的 Chrome - 路由器问题

ios - AppDelegate Extension 未被调用

ios - XCode 找不到错误的 .app 文件

ios - self.navigationController 使用 Storyboard到 Storyboard导航始终返回 nil

iphone - 通过 UIPasteBoard 在短信中粘贴图像

javascript - iphone 的 jplayer 错误