I have an iPad with an external touchscreen. I am trying to remap the coordinate system of the external touchscreen to the UIWindow that is shown there.
I am getting the touches on the UIViewController of the UIWindow that is displayed on the iPad, as if I was touching the iPad. I do get them with the touchtype .stylus, which is how I can distinguish them from actual iPad touches (I will show different views on the iPad and the external screen). I am using the following code:
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)
}
}
I am trying to pass the touches along to the second UIWindow, as if I were touching there. But that does not seem to work.
How can I touch a view programmatically? I am testing now with a button on the second screen, but it will need to work with SceneKit views as well.
from How to remap a touch to another window?
No comments:
Post a Comment