Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Traversing the View Hierarchy on an iPhone or iPad [duplicate]

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?

like image 963
Kartick Vaddadi Avatar asked Mar 01 '11 03:03

Kartick Vaddadi


People also ask

How to debug view hierarchy?

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.

How do you view a hierarchy?

In the menu bar, select Window > Open Perspective, and then click Hierarchy View.

What is responder chain swift?

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.

What is UIResponder in IOS?

An abstract interface for responding to and handling events.


2 Answers

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.

like image 123
Simon Goldeen Avatar answered Oct 05 '22 04:10

Simon Goldeen


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.

like image 26
Levi McCallum Avatar answered Oct 05 '22 05:10

Levi McCallum