Glance

Glance 是一个轻量级的库,它允许你直接从你的移动设备或模拟器调试视图层级。

安装

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/nikitabelopotapov/Glance.git", .upToNextMajor(from: "0.0.1"))
]

用法

建议的使用方法是在 UIWindow 扩展中将 Glance 附加到摇晃手势。

import Glance

extension UIWindow {
    open override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
        super.motionEnded(motion, with: event)
        if motion == .motionShake {
            Glance.main.debug(view: self)
        }
    }
}

自定义视图

如果你有任何自定义或不支持的视图(例如在 CGContext 中绘制内容的视图),你可以提供自定义。

final class CustomLayoutProvider: LayoutProvidable {
    var layoutMapper: LayoutMappable?
    
    func provide(for view: UIView, depth: inout Float, masterView: UIView?) -> [LayoutSnapshot] {
        return [LayoutSnapshot(image: UIImage(), depth: 1, frame: .zero, view: view)]
    }
}

然后将其添加到 Glance 布局提供程序。

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

	func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        Glance.main.addLayoutProvider(provider: CustomLayoutProvider(), viewClass: MyCustomClass.Type)
		return true
	}
}

视图属性 (Beta)

通过点击 Glance 主屏幕中的任何视图,你可以检查视图属性。目前此功能尚未完全实现。

贡献

欢迎提交 Pull request 或 issue