I use a hosting controller to present specific views above .sheets and .fullscreencovers. When I present these small views using the hosting controller then all the background views get disabled. How can I make it so that both the background views and hosting controller view both detect user interaction. In my case the video presented by the hosting controller only takes up a corner of the screen (the video is floating and can be dragged to any corner of the screen), the video can also be clicked and then expands to the full screen. If this is not possible with a hosting controller is there a different way to present a view about everything, including .sheets and .fullscreencover?
note my question was marked as a duplicate however if you look at the answer posted at the other question they propose exactly what I do below, which does not work. Please reopen this question for answers. Setting “isUserInteractionEnabled” passes touches through a view and disregards gestures to the overlay view. I do not want this. I want both views to detect gestures.
I tried doing hostingController?.view.isUserInteractionEnabled = false but then this enables interaction with the background and disables the hosting controller.
struct SomeView: View {
var body: some View {
ScrollView {
//some content
}
}
}
struct ContentView: View {
var body: some View {
SomeView()
.overlay {
TopVideoView()
}
}
}
struct TopView: View {
var body: some View {
RoundedRectangle(cornerRadius: 10)
.foregroundStyle(.blue).frame(width: 100, height: 100)
}
}
struct TopVideoView: View {
@State private var hostingController: UIHostingController<TopView>? = nil
func showImage() {
let swiftUIView = TopView()
hostingController = UIHostingController(rootView: swiftUIView)
hostingController?.view.backgroundColor = .clear
hostingController?.view.frame = CGRect(
x: 0,
y: 0,
width: UIScreen.main.bounds.width,
height: UIScreen.main.bounds.height)
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first {
window.addSubview(hostingController!.view)
hostingController?.view.center.x = window.center.x
}
}
func dismissImage() {
hostingController?.view.removeFromSuperview()
hostingController = nil
}
var body: some View {
VStack {}
.onAppear { showImage() }
.onDisappear { dismissImage() }
}
}


