Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

Issue with Animations Blocking Taps in UIView Toasts (SwiftUI + Separate UIWindow)

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:

  1. Using a separate UIWindow to present the toast overlay.
  2. Adding a tap gesture directly to the UIView.
  3. 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

Could you post the relevant code for animation (to avoid the need to download the whole project).

Did you enable userInteraction (allowUserInteraction)?

See details here: https://stackoverflow.com/questions/7337363/how-to-recognize-tap-gesture-while-a-view-is-animating

Accepted Answer

This code has the problem I encountered

    // Fade in and rise up animation
        UIView.animate(withDuration: 0.3, animations: {
            self.alpha = 1
            self.frame.origin.y -= 50
        }) { _ in
            UIView.animate(withDuration: 0.3, delay: duration, animations: {
                
                self.alpha = 0
                self.frame.origin.y += 50 // Moves down
            }) { _ in
                self.removeFromSuperview()
            }
        }

This snippet shows the fix

// Fade in and rise up animation
        UIView.animate(withDuration: 0.3, animations: {
            self.alpha = 1
            self.frame.origin.y -= 50
        }) { _ in
            // This dispatchQueue will allow tap events, it's not acceptable to use the delay parameter from UIView.animate()
            DispatchQueue.main.asyncAfter(deadline: .now() + duration) {
                UIView.animate(withDuration: 0.3, animations: {
                    
                    self.alpha = 0
                    self.frame.origin.y += 50 // Moves down
                }) { _ in
                    self.removeFromSuperview()
                }
            }
        }
Issue with Animations Blocking Taps in UIView Toasts (SwiftUI + Separate UIWindow)
 
 
Q