Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ignoresSafeArea not covering bottom of View

Tags:

swiftui

I'm trying to create the background for a background view for a popup, however the view doesn't cover the bottom even after I use .ignoreSafeArea().

import SwiftUI

struct Overlay<Content: View>: View {

    @State var opacity: Double = 0
    var content: Content

    var body: some View {
        VStack {
            Color.black.opacity(opacity).ignoresSafeArea()
            content
        }
        .onAppear { self.opacity = 0.5 }
        .onDisappear { self.opacity = 0 }
    }
}

struct ForgotPasswordView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            Overlay(content: Text(""))
                .previewDevice("iPhone 12")
        }
    }
}

enter image description here

like image 761
ScottyBlades Avatar asked Oct 17 '25 21:10

ScottyBlades


1 Answers

VStack arranges its children in a vertical line.

What You see in the bottom area is your content which you pass in the view creation (here its your TextView).

struct Overlay<Content: View>: View {

    @State var opacity: Double = 0
    var content: Content

    var body: some View {
        ZStack { //<- here
            Color.black.opacity(opacity).ignoresSafeArea()
            content
        }
        .onAppear { self.opacity = 0.5 }
        .onDisappear { self.opacity = 0 }
    }
}
like image 95
Yodagama Avatar answered Oct 19 '25 12:10

Yodagama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!