0

This is what I want to achieve: enter image description here

This is what I got: enter image description here

I tried embeding the VStack in another VStack with a .background(.gray.opacity(90)) but it didn't do anything. I am using a fullScreenCover:

let width = UIScreen.main.bounds.width
.fullScreenCover(isPresented: $showCover) {
BuyWithPointsView(type: type).frame(width: (width * (91.733 / 100)), height: (width * (66.667 / 100)))
}

EDIT: I tried implementing this answer: SwiftUI: Translucent background for fullScreenCover

.fullScreenCover(isPresented: $showCover) {
                    ZStack {
                        ZStack {
                            Color.gray.opacity(0.1).edgesIgnoringSafeArea(.all)
                        }.background(BackgroundBlurView())
                        BuyWithPointsView(type: type).frame(width: (width * (91.733 / 100)), height: (width * (66.667 / 100)))
                    }
                }
struct BackgroundBlurView: UIViewRepresentable {
    func makeUIView(context: Context) -> UIView {
        let view = UIVisualEffectView(effect: UIBlurEffect(style: .light))
        DispatchQueue.main.async {
            view.superview?.superview?.backgroundColor = .clear
        }
        return view
    }
    func updateUIView(_ uiView: UIView, context: Context) {}
}

This lead to this result: enter image description here However this result does not really make the background see through like I want it to be. Changing the opacity and color didn't do much.

AdamLeet
  • 127
  • 8
  • Does this answer your question? [Is there a way to set a fullScreenCover background opacity?](https://stackoverflow.com/questions/65295388/is-there-a-way-to-set-a-fullscreencover-background-opacity) – soundflix Aug 30 '23 at 07:48

2 Answers2

1

I found this cleaner solution for the transparent background without any flicker issues.

struct ClearBackgroundView: UIViewRepresentable {
    func makeUIView(context: Context) -> UIView {
        return InnerView()
    }
    
    func updateUIView(_ uiView: UIView, context: Context) {
    }
    
    private class InnerView: UIView {
        override func didMoveToWindow() {
            super.didMoveToWindow()
            
            superview?.superview?.backgroundColor = .clear
        }
        
    }
}

Usage

PresenterView()
    .fullScreenCover(isPresented: $isPresented) {
        PresentedView()
            .background(ClearBackgroundView())
    }
Ahmed M. Hassan
  • 709
  • 9
  • 14
0

iOS 16.4 provides .presentationBackground to modify your modal backgrounds. Yay to yoinking UIViewRepresentable workarounds :)

Usage

.fullScreenCover(isPresented: $isPresented) {
    YourView()
        .presentationBackground(.clear)
}
Aurevoir
  • 46
  • 3