iOS上视图层次的可视化

时间:2021-07-20 08:32:25

Whilst developing iOS apps I found using po [[UIWindow keyWindow] recursiveDescription] in the debugger very useful. However, I am wondering whether there is a tool to gracefully represent the output for better readability?

在开发iOS应用时,我发现在调试器中使用po [[UIWindow keyWindow] recursiveDescription]非常有用。但是,我想知道是否有一个工具可以优雅地表示输出,以获得更好的可读性?

5 个解决方案

#1


1  

I usually use po but I found this tool awhile ago and meant to try it out but haven't.

我通常使用po,但是我在一段时间以前发现了这个工具,并打算尝试它,但还没有。

It embeds itself in your app and exposes itself as a little web app so you can view the state of the view hierarchy while you use the app.

它将自己嵌入到你的应用中,并将自己公开为一个小web应用,这样你就可以在使用这个应用时查看视图层次结构的状态。

http://blog.thepete.net/blog/2011/05/01/inspect-state-of-our-running-ios-apps/

http://blog.thepete.net/blog/2011/05/01/inspect-state-of-our-running-ios-apps/

EDIT:

编辑:

Adding sparkinpector which was mentioned in the comments. I checked it out and it seems very cool - especially if you create views programmatically.

在评论中提到的添加备件。我检查过它,它看起来很酷——特别是如果您以编程的方式创建视图。

#2


2  

here is a method I wrote back in the days:

这是我以前写的一个方法:

- (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]; }
}

call it like so: [self logView:myView index:0];

[self logView:myView index:0];

sample output:

样例输出:

<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}}>

#3


0  

There definitely are. We've come a long way in the last few years, and -recursiveDescription is a pretty painful way to see your view hierarchy - especially when your interface is complex. Take a look at this answer for some newer solutions:

肯定有。在过去的几年里,我们已经取得了长足的进步,递归描述是查看视图层次结构的一种非常痛苦的方式——尤其是当您的接口非常复杂的时候。看看下面这些更新的解决方案:

I need to inspect the view hierarchy on an iPhone program

我需要检查iPhone程序的视图层次结构

#4


0  

Use reveal app: http://revealapp.com.

使用显示应用程序:http://revealapp.com。

This might help.

这可能会有所帮助。

#5


0  

Here is one private way,

这里有一个私人的方法,

write following code,

写代码,

NSLog("%@",[[[UIApplication sharedApplication] keyWindow] performSelector(@selector(recursiveDescription))]);

similarly for any view:

同样的观点:

NSLog("%@",[view performSelector(@selector(recursiveDescription))]);

this will give you the whole view hierarchy.

这将为您提供整个视图层次结构。

Please make note that, dont submit your code to apple after using this method in your application, because this is private api. Just, use these for only debugging purpose.

请注意,在应用程序中使用此方法后,不要将代码提交给apple,因为这是私有api。只是,仅将它们用于调试目的。

#1


1  

I usually use po but I found this tool awhile ago and meant to try it out but haven't.

我通常使用po,但是我在一段时间以前发现了这个工具,并打算尝试它,但还没有。

It embeds itself in your app and exposes itself as a little web app so you can view the state of the view hierarchy while you use the app.

它将自己嵌入到你的应用中,并将自己公开为一个小web应用,这样你就可以在使用这个应用时查看视图层次结构的状态。

http://blog.thepete.net/blog/2011/05/01/inspect-state-of-our-running-ios-apps/

http://blog.thepete.net/blog/2011/05/01/inspect-state-of-our-running-ios-apps/

EDIT:

编辑:

Adding sparkinpector which was mentioned in the comments. I checked it out and it seems very cool - especially if you create views programmatically.

在评论中提到的添加备件。我检查过它,它看起来很酷——特别是如果您以编程的方式创建视图。

#2


2  

here is a method I wrote back in the days:

这是我以前写的一个方法:

- (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]; }
}

call it like so: [self logView:myView index:0];

[self logView:myView index:0];

sample output:

样例输出:

<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}}>

#3


0  

There definitely are. We've come a long way in the last few years, and -recursiveDescription is a pretty painful way to see your view hierarchy - especially when your interface is complex. Take a look at this answer for some newer solutions:

肯定有。在过去的几年里,我们已经取得了长足的进步,递归描述是查看视图层次结构的一种非常痛苦的方式——尤其是当您的接口非常复杂的时候。看看下面这些更新的解决方案:

I need to inspect the view hierarchy on an iPhone program

我需要检查iPhone程序的视图层次结构

#4


0  

Use reveal app: http://revealapp.com.

使用显示应用程序:http://revealapp.com。

This might help.

这可能会有所帮助。

#5


0  

Here is one private way,

这里有一个私人的方法,

write following code,

写代码,

NSLog("%@",[[[UIApplication sharedApplication] keyWindow] performSelector(@selector(recursiveDescription))]);

similarly for any view:

同样的观点:

NSLog("%@",[view performSelector(@selector(recursiveDescription))]);

this will give you the whole view hierarchy.

这将为您提供整个视图层次结构。

Please make note that, dont submit your code to apple after using this method in your application, because this is private api. Just, use these for only debugging purpose.

请注意,在应用程序中使用此方法后,不要将代码提交给apple,因为这是私有api。只是,仅将它们用于调试目的。