如何检查iOS中的视图层次结构?

时间:2022-06-01 21:04:38

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.

是否有GUI工具来检查iOS应用程序的视图层次结构?我在想Webkit的网络检查器或者类似的工具。我希望调试布局问题,比如位置或大小错误的视图,或者父视图中没有正确包含子视图。现在我必须添加断言,用手工测试这些不同的条件,或者在不同的视图上设置不同的背景颜色,你可以想象,这是一种非常乏味的方法。

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.

我查看了Instruments公司的用户界面记录器,但它只记录并回放用户界面操作,而且无论如何,它只适用于Mac应用程序。

Is there a better solution?

有更好的解决方案吗?

10 个解决方案

#1


144  

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

Xcode 6现在有了3D视图层次结构检查,它内置了一个显示应用程序和Spark Inspector。

如何检查iOS中的视图层次结构?

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

当您的应用程序运行时,单击“调试视图层次结构”按钮以暂停执行,并在当前时刻检查视图。

如何检查iOS中的视图层次结构?

More info at Apple's documentation.

更多信息请参阅苹果的文档。

#2


258  

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

我不知道是否有GUI视图检查工具,但是我对UIView: -recursiveDescription上的调试方法有一些了解

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

如果您在调试器中暂停程序并将其输入到GDB(编辑:在LLDB中也可以)

po [[UIWindow keyWindow] recursiveDescription]

阿宝[[ui窗口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.

这篇博客讨论了这个方法,也链接了这个有用的,但是很难找到苹果技术笔记。

#3


46  

如何检查iOS中的视图层次结构?

Oddly enough, now there is another option, http://revealapp.com/, which as of this post is in an open (free) beta. As you can see it's another visual inspector.

奇怪的是,现在有另一个选项http://revealapp.com/,在这篇文章中它是一个开放的(免费的)测试版。你可以看到它是另一个视觉检查器。

EDIT 2014-04-05: Reveal is out of Beta and no longer free. There is a 30-day trial, however.

编辑2014-04-05:揭示已经超出测试,不再免费。然而,有一个30天的试验。

#4


34  

This question is old but let me put info here about new tool which I develop: https://github.com/glock45/iOS-Hierarchy-Viewer 如何检查iOS中的视图层次结构?

这个问题已经过时了,但是让我在这里介绍一下我开发的新工具:https://github.com/glock45/ios-- viewer。

#5


17  

如何检查iOS中的视图层次结构?

Just to keep this thread up to date, I've been recently playing with Spark Inspector. It's not free, but it's very nice.

为了让这个线程保持最新,我最近一直在玩Spark Inspector。这不是免费的,但很好。

#6


6  

Free : Just type this in inspector :

免费:在检查器中输入:

po [[UIWindow keyWindow] recursiveDescription]

Commercial : http://revealapp.com/ I tested beta version of revealapp, it was good though has bugs. Another Commercial tool : http://sparkinspector.com/ it's working seamless.

商业:http://revealapp.com/我测试了这个应用的测试版,虽然有漏洞,但还是不错的。另一个商业工具:http://sparkinspector.com/它无缝工作。

#7


5  

The FLEX Debugger provides an in app view inspector that allows you to modify the UI in a running app. It also logs network requests.

FLEX调试器提供了一个内视图检查器,允许您在运行的应用程序中修改UI。

https://github.com/Flipboard/FLEX

https://github.com/Flipboard/FLEX

如何检查iOS中的视图层次结构?

#8


3  

Swift 4.

斯威夫特4。

iOS:

iOS:

extension UIView {

   // Prints results of internal Apple API method `recursiveDescription` to console.
   public func dump() {
      Swift.print(perform(Selector(("recursiveDescription"))))
   }
}

macOS:

macOS:

extension NSView {

   // Prints results of internal Apple API method `_subtreeDescription` to console.
   public func dump() {
      Swift.print(perform(Selector(("_subtreeDescription"))))
   }
}

Usage (in debugger): po myView.dump()

用法(在调试器中):po myView.dump()

#9


2  

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

这将在调试窗口中转储所有内容。(很难读懂tho):(操作iOS 10, Xcode 8.3.3

po UIApplication.shared.keyWindow?.recursiveDescription()

#10


0  

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

使用Xcode 8和Swift 2.3,批准的答案对我不再适用。以下是我的工作:

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

阿宝UIApplication.sharedApplication().keyWindow ? .recursiveDescription()

#1


144  

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

Xcode 6现在有了3D视图层次结构检查,它内置了一个显示应用程序和Spark Inspector。

如何检查iOS中的视图层次结构?

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

当您的应用程序运行时,单击“调试视图层次结构”按钮以暂停执行,并在当前时刻检查视图。

如何检查iOS中的视图层次结构?

More info at Apple's documentation.

更多信息请参阅苹果的文档。

#2


258  

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

我不知道是否有GUI视图检查工具,但是我对UIView: -recursiveDescription上的调试方法有一些了解

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

如果您在调试器中暂停程序并将其输入到GDB(编辑:在LLDB中也可以)

po [[UIWindow keyWindow] recursiveDescription]

阿宝[[ui窗口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.

这篇博客讨论了这个方法,也链接了这个有用的,但是很难找到苹果技术笔记。

#3


46  

如何检查iOS中的视图层次结构?

Oddly enough, now there is another option, http://revealapp.com/, which as of this post is in an open (free) beta. As you can see it's another visual inspector.

奇怪的是,现在有另一个选项http://revealapp.com/,在这篇文章中它是一个开放的(免费的)测试版。你可以看到它是另一个视觉检查器。

EDIT 2014-04-05: Reveal is out of Beta and no longer free. There is a 30-day trial, however.

编辑2014-04-05:揭示已经超出测试,不再免费。然而,有一个30天的试验。

#4


34  

This question is old but let me put info here about new tool which I develop: https://github.com/glock45/iOS-Hierarchy-Viewer 如何检查iOS中的视图层次结构?

这个问题已经过时了,但是让我在这里介绍一下我开发的新工具:https://github.com/glock45/ios-- viewer。

#5


17  

如何检查iOS中的视图层次结构?

Just to keep this thread up to date, I've been recently playing with Spark Inspector. It's not free, but it's very nice.

为了让这个线程保持最新,我最近一直在玩Spark Inspector。这不是免费的,但很好。

#6


6  

Free : Just type this in inspector :

免费:在检查器中输入:

po [[UIWindow keyWindow] recursiveDescription]

Commercial : http://revealapp.com/ I tested beta version of revealapp, it was good though has bugs. Another Commercial tool : http://sparkinspector.com/ it's working seamless.

商业:http://revealapp.com/我测试了这个应用的测试版,虽然有漏洞,但还是不错的。另一个商业工具:http://sparkinspector.com/它无缝工作。

#7


5  

The FLEX Debugger provides an in app view inspector that allows you to modify the UI in a running app. It also logs network requests.

FLEX调试器提供了一个内视图检查器,允许您在运行的应用程序中修改UI。

https://github.com/Flipboard/FLEX

https://github.com/Flipboard/FLEX

如何检查iOS中的视图层次结构?

#8


3  

Swift 4.

斯威夫特4。

iOS:

iOS:

extension UIView {

   // Prints results of internal Apple API method `recursiveDescription` to console.
   public func dump() {
      Swift.print(perform(Selector(("recursiveDescription"))))
   }
}

macOS:

macOS:

extension NSView {

   // Prints results of internal Apple API method `_subtreeDescription` to console.
   public func dump() {
      Swift.print(perform(Selector(("_subtreeDescription"))))
   }
}

Usage (in debugger): po myView.dump()

用法(在调试器中):po myView.dump()

#9


2  

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

这将在调试窗口中转储所有内容。(很难读懂tho):(操作iOS 10, Xcode 8.3.3

po UIApplication.shared.keyWindow?.recursiveDescription()

#10


0  

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

使用Xcode 8和Swift 2.3,批准的答案对我不再适用。以下是我的工作:

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

阿宝UIApplication.sharedApplication().keyWindow ? .recursiveDescription()