swiftswiftuiinteraction

Allow user interaction in views behind a fullScreenCover in SwiftUI


I have a view that shows an animation briefly that needs to be in front of everything (including on top of any presented sheets which means a ZStack or .overlay will not work). .fullScreenCover works, however, it blocks any interaction with the content underneath and I'd really like to not block interaction. I have tried .allowsHitTesting(false) and .presentationBackgroundInteraction(.enabled) but neither of those seem to work with .fullScreenCover. Does anyone know of a way to do this purely in SwiftUI? I think there might be some ways with a scene delegate and going through UIKit, but I'd really rather not do that...


Solution

  • The solution is to create an .overlay on the top-most view in the WindowGroup and in the view in the .overlay use .allowsHitTesting(false) to disable interaction and pass taps through to underlying views.