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?
First, launch a project with some interesting UI. Project 13, for example, has enough in there to be interesting. Now run the program as normal, then in Xcode go to the Debug menu and choose View Debugging > Capture View Hierarchy. After a few seconds of thinking, Xcode will show you a screenshot of your app's UI.
In the menu bar, select Window > Open Perspective, and then click Hierarchy View.
The responder chain is the series of events that happen once we start interacting with the application on the iPhone. As an example, whenever we tap on an UITextfield, the whole series of responder initiates. It happens because of elements like UIView, UIViewController, UIApplication subclass UIResponder.
An abstract interface for responding to and handling events.
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 you pause the program in the debugger and input this into GDB (Edit: also works in LLDB)
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.
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.
Xcode 6 now has 3D view hierarchy inspection built in like Reveal App and Spark Inspector.
Click on the "Debug View Hierarchy" button while your app is running to pause execution and inspect the views at the current moment.
More info at Apple's documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With