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
}
}
通过点击 Glance 主屏幕中的任何视图,你可以检查视图属性。目前此功能尚未完全实现。