2012-07-27 33 views
3

视图层次的发展虽然iOS应用,我发现在调试器非常有用使用po [[UIWindow keyWindow] recursiveDescription]。但是,我想知道是否有一个工具可以优雅地表示输出以提高可读性?可视化在iOS

+0

超越'po'?不是真的,不是。 – 2012-07-27 12:26:55

+0

这看起来很花哨:http://revealapp.com – omz 2013-06-05 23:58:37

回答

1

我通常使用PO,但我前一段时间发现这个工具,并打算尝试一下,但没有。

它本身嵌入在你的应用程序,并公开本身作为一个小的Web应用程序,因此您可以在您使用的应用程序查看视图层次的状态。

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

编辑:

添加这是在评论中提到sparkinpector。我检查了它,它看起来非常酷 - 特别是如果您以编程方式创建视图。

+0

看起来很有希望。谢谢 – HeikoG 2012-07-27 13:09:32

+1

你可能还想看看DCIntrospect(https://github.com/domesticcatsoftware/DCIntrospect)和Spark Inspector(http://www.sparkinspector.com)。它们更新,不需要对应用程序进行归化。 (完全披露 - 我是Spark Inspector的作者!) – 2013-06-02 19:46:45

+0

Ben - 非常酷。将检查出来。 – bryanmac 2013-06-05 23:22:28

2

这里是一个方法,我在天回信:

- (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}}> 
+1

感谢您分享此内容。它看起来很像recursiveDescription输出,对吗? – HeikoG 2012-07-27 13:09:06

+0

比它短。例如。许多对象有像标题和字体,类型等更多的描述值,但可以通过'appendFormat调整格式:''方法<%@%P帧:%@>' – 2012-07-27 13:35:32

+0

啊 - 好,我看到的。谢谢澄清 – HeikoG 2012-07-27 14:26:36

0

有绝对的。在过去的几年中,我们走过了很长的一段路,而看到您的视图层次结构时,-recursiveDescription是一种相当痛苦的方式 - 尤其是当您的界面非常复杂时。看看这个答案对于一些较新的解决方案:

I need to inspect the view hierarchy on an iPhone program

0

这是一个私人的方式,

写下面的代码,

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

同样,对于任何观点:

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

这会给你整个视图层次结构。

请注意,不要在你的应用程序中使用此方法后,你的代码提交给苹果,因为这是私有API。只是,只用于调试目的。