【发布时间】:2020-02-14 08:05:26
【问题描述】:
我有一台带外接触摸屏的 iPad。我正在尝试将外部触摸屏的坐标系重新映射到那里显示的UIWindow。
我正在触摸 iPad 上显示的 UIWindow 的 UIViewController,就好像我在触摸 iPad。我确实使用触摸类型.stylus 来获取它们,这就是我如何将它们与实际的 iPad 触摸区分开来(我将在 iPad 和外部屏幕上显示不同的视图)。我正在使用以下代码:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touchesOnExternalWindow = touches.filter({ $0.type == .stylus })
let touchesOnIpad = touches.subtracting(touchesOnExternalWindow)
if !touchesOnIpad.isEmpty {
super.touchesBegan(touchesOnIpad, with: event)
}
if !touchesOnExternalWindow.isEmpty {
guard let externalWindow = UIApplication.shared.windows.first(where: { $0.screen.bounds == screenBounds }) else {
fatalError("Touching the external display without an external display is not supported!")
}
externalWindow.rootViewController?.view.touchesBegan(touchesOnExternalWindow, with: event)
}
}
我试图将触摸传递给第二个UIWindow,就好像我在触摸那里一样。但这似乎不起作用。
如何以编程方式触摸视图?我现在正在使用第二个屏幕上的按钮进行测试,但它也需要与 SceneKit 视图一起使用。
【问题讨论】:
标签: ios uiresponder