如何将触摸重新映射到另一个窗口?
我有一台带外置触摸屏的iPad。我正在尝试将外部触摸屏的坐标系重新映射到那里显示的UIWindow
。
我正在触摸iPad上显示的UIWindow
的UIViewController
,就像我正在触摸iPad一样。我确实通过touchtype .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视图一起工作。
转载请注明出处:http://www.jlgayy.com/article/20230526/1573293.html