我们如何在 SwiftUI 中使用渐变模糊形状?

How can we Blur a Shape with Gradient in SwiftUI?

试图用渐变模糊我的圆圈,但无法弄清楚为什么它不起作用。任何人有想法或者这还不支持吗?

struct GradientExperiment: View {
var body: some View {
    VStack {
        //blur works
        Circle()
            .fill(Color(.blue))
            .frame(width: 50, height: 50)
            .blur(radius: 10)

        //blur does not work
        Circle()
            .fill(LinearGradient(gradient: Gradient(colors: [.blue,.red]), startPoint: .bottom, endPoint: .top))
            .frame(width: 50, height: 50)
            .blur(radius: 10)
    }
}

}

为您的 LinearGradient 添加掩码并使用 Circle 作为掩码:

LinearGradient(gradient: Gradient(colors: [.blue, .red]), startPoint: .bottom, endPoint: .top)
  .mask(
    Circle()
      .frame(width: 50, height: 50)
      .blur(radius: 10)
    )