ios - Make the background of a sheet presented in a fullScreenCover translucent? - Stack Overflow

I have a fullScreenCover, which then presents another sheet on top of it. I want this sheet to be trans

I have a fullScreenCover, which then presents another sheet on top of it. I want this sheet to be translucent so I can apply materials over it. I had it working here:

struct ClearBackgroundView: UIViewRepresentable {
    func makeUIView(context: Context) -> some UIView {
        let view = UIView()
        DispatchQueue.main.async {
            view.superview?.superview?.backgroundColor = .clear
        }
        return view
    }
    
    func updateUIView(_ uiView: UIViewType, context: Context) {
    }
}

struct ClearBackgroundViewModifier: ViewModifier {
    
    func body(content: Content) -> some View {
        content
            .background(ClearBackgroundView())
    }
}

extension View {
    func clearModalBackground() -> some View {
        self.modifier(ClearBackgroundViewModifier())
    }
}

This is then called on a view like so:

StopDetail(coreStop: stop)
                .clearModalBackground()
                .background(
                        Color.background.opacity(0.7)
                            .ignoresSafeArea()
                            .background(.ultraThinMaterial))

This method works whenever the view isn't inside a fullScreenCover. If it's being presented from a fullScreenCover, this won't work, and the view will have a normal background as if my code doesn't do anything. From the hierarchy debugger, the view that's adding the background appears to be a PresentationHostingController (class UIHostingView).

How can I fix this?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744379103a4571334.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信