如何在 Swift Playground 中获取布局跟踪

Pet*_*her 2 xcode ios swift swift-playground

我正在 Swift Playground 中制作一些视图的原型。

import UIKit
import XCPlayground

let containerView = UIView(frame: CGRect(origin: CGPointZero, size: CGSize(width: 320, height: 300)))

XCPShowView("Container View", containerView)
Run Code Online (Sandbox Code Playgroud)

我正在使用此容器视图来放入一些视图并使用约束对其进行布局。现在我真的很想从中获得一个 LayoutTrace,就像来自

po [[UIWindow keyWindow] _autolayoutTrace]
Run Code Online (Sandbox Code Playgroud)

这将使我能够轻松找到一些模棱两可的布局。

有任何想法吗?

Ale*_*lav 5

您可以使用 Objective-C 运行时从 Swift PlaygroundvalueForKey访问_autolayoutTrace

print(containerView.valueForKey("_autolayoutTrace"))
Run Code Online (Sandbox Code Playgroud)