如何在iOS中检查视图层次结构? [英] How do I inspect the view hierarchy in iOS?

查看:122
本文介绍了如何在iOS中检查视图层次结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个GUI工具检查iOS应用程序的视图层次结构?我正在考虑Webkit的Web检查器或类似工具。我想调试布局问题,如视图具有错误的位置或大小,或孩子没有正确包含在其父。目前,我要添加断言,手动测试这些各种条件,或设置不同的背景颜色在不同的视图,你可以想象,这是一个非常乏味的方式去处理。

Is there a GUI tool that inspects the view hierarchy of an iOS app? I'm thinking about Webkit's web inspector or similar tools. I'm looking to debug layout issues, like views having the wrong position or size, or a child not being properly contained in its parent. Currently I have to add asserts that test these various conditions by hand, or set different background colours on different views, and as you can imagine, that's a really tedious way to go about it.

我看过Instruments的 UI录音机,但只记录和播放UI操作,并且在任何情况下只适用于Mac应用程序。

I looked at Instruments's UI recorder, but that only records and plays back UI actions` and, in any case, works only for Mac apps.

有更好的解决方案吗?

推荐答案

我不知道一个GUI视图检查工具,但我有一些运气与UIView的调试方法: -recursiveDescription

I don't know if there is a GUI view inspection tool, but I have had some luck with the debugging method on UIView: -recursiveDescription

if您在调试器中暂停程序并将其输入到GDB(编辑:也在LLDB中工作)

if you pause the program in the debugger and input this into GDB ( also works in LLDB)


po [[UIWindow keyWindow] recursiveDescription]

po [[UIWindow keyWindow] recursiveDescription]

您将获得整个视图层次结构的打印输出。您也可以在特定视图中调用它,以获取该视图的视图层次结构的打印输出。

You get a printout of your entire view hierarchy. You can also call it on a specific view to get a printout of the view hierarchy of that view.

您可以花费一些繁琐的工作

It can be a little tedious to wade through the info you get out of it, but it has proved useful to me.

信用本博文,其中讨论了此方法,并链接到这有帮助,但很难找到Apple技术说明

Credit goes to this blog post which talked about this method and also linked to this helpful, but rather hard to find Apple tech note.

这篇关于如何在iOS中检查视图层次结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆