TouchInspector 是一个轻量级的软件包,可帮助你在 iOS 和 iPadOS 上可视化和调试触摸事件。
在录制和分享设备或模拟器上的演示时,显示触摸事件非常有用。
TouchInspector 还可以选择显示点击测试信息(即触摸点命中的视图)。这在尝试识别某个视图的类型或调试触摸实际发生的位置时非常有用。
将 TouchInspector 添加到你的应用程序的 Package.swift
文件中,或者在 Xcode 中选择 File -> Add Packages
.package(url: "https://github.com/jtrivedi/TouchInspector", from: "0.1.0"))
你需要将应用程序/场景的 window
类型更改为 TouchInspectorWindow
,你可以在开发时有条件地执行此操作
import TouchInspector
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else {
return
}
let rootViewController = /* Create your root/initial view controller,
either directly or by extracting from a Storyboard */
#if DEBUG
window = TouchInspectorWindow(windowScene: windowScene)
#else
window = UIWindow(windowScene: windowScene)
#endif
window?.rootViewController = rootViewController
window?.makeKeyAndVisible()
}
默认情况下,创建 TouchInspectorWindow
时会启用触摸**和**点击测试可视化。你可以使用以下属性更改它
// Show the touch indicator, but not the hit-testing overlay.
window.showTouches = true
window.showHitTesting = false