Edit: Well this is embarassing. It looks like I didn't research this thoroughly enough, animations block UIVIew tap events. I found a solution by using DispatchQueue
I ran into an unexpected issue when presenting a UIView-based toast inside a separate UIWindow
in a SwiftUI app. Specifically, when animations are applied to the toast view (UIToastView
), the tap gesture no longer works.
To help identify the root cause, I created a minimal reproducible example (MRE) with under 500 lines of code, demonstrating the behavior:
Demo GIF: Screen Recording
Code Repo: ToastDemo
What I Tried:
- Using a separate UIWindow to present the toast overlay.
- Adding a tap gesture directly to the
UIView
. - Referencing related solutions:
- A Blog Post explaining UIWindow usage in SwiftUI - https://www.fivestars.blog/articles/swiftui-windows (Sorry, Apple Dev Forum will not allow a link to this)
- A Stack Overflow thread on handling touch events in multiple windows.
Problem Summary:
- When animations are involved (fade in, slide up), taps on the toast are not recognized.
- Without animations, taps work as expected.
- UIWindow setup seems correct, so I’m wondering if animation effects are interfering with event propagation.
I could potentially work around this by restructuring the touch handling, but I'd love insight from the community on why this happens, or if there’s a cleaner fix.
Edit: Well this is embarassing. It looks like I didn't research this thoroughly enough, animations block UIVIew tap events. I found a solution by using DispatchQueue