SwiftUI 如何从底部边缘淡出图像

SwiftUI How to Fade an Image out from the bottom Edge

基本上我想要实现的是:

从上到下淡出图像。我试着用叠加层来做,但它看起来不太好

这是一个从上到下淡出图像的工作视图。 Lmk 如果它有效!

源代码

struct ContentView: View {
    var body: some View {
        VStack {
            Image("Explore")//Your Image
                .resizable()
        }
        //We can use the LinearGradient in the mask modifier to fade it top to bottom
        .mask(LinearGradient(gradient: Gradient(stops: [
            .init(color: .black, location: 0),
            .init(color: .clear, location: 1),
            .init(color: .black, location: 1),
            .init(color: .clear, location: 1)
        ]), startPoint: .top, endPoint: .bottom))
        .padding()
        .frame(width: 400, height: 400)
    }
}

预览