How do I inspect the view hierarchy in iOS?

2019-01-01 11:54发布

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.

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.

Is there a better solution?

10条回答
怪性笑人.
2楼-- · 2019-01-01 12:27

The approved answer no longer works for me, using Xcode 8 and Swift 2.3. Here's what does work for me:

po UIApplication.sharedApplication().keyWindow?.recursiveDescription()

查看更多
旧人旧事旧时光
3楼-- · 2019-01-01 12:28

This question is old but let me put info here about new tool which I develop: https://github.com/glock45/iOS-Hierarchy-Viewer enter image description here

查看更多
墨雨无痕
4楼-- · 2019-01-01 12:32

This dumps all in debug window.(Hard to read tho) :( Working on iOS 10, Xcode 8.3.3

po UIApplication.shared.keyWindow?.recursiveDescription()
查看更多
呛了眼睛熬了心
5楼-- · 2019-01-01 12:36

Xcode 6 now has 3D view hierarchy inspection built in like Reveal App and Spark Inspector.

enter image description here

Click on the "Debug View Hierarchy" button while your app is running to pause execution and inspect the views at the current moment.

enter image description here

More info at Apple's documentation.

查看更多
登录 后发表回答