我目前正在开发一个应用程序,想知道如何能够以能够创建如此大模糊的方式来设计任务。
我已经创建了一个原型,但它几乎不能正常工作,但这是我的代码。
struct BlurView: UIViewRepresentable {
var style: UIBlurEffect.Style
var opacity: Double
func makeUIView(context: Context) -> UIVisualEffectView {
let blurView = UIVisualEffectView(effect: UIBlurEffect(style: style))
blurView.clipsToBounds = true
blurView.alpha = CGFloat(opacity)
return blurView
}
func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
uiView.effect = UIBlurEffect(style: style)
uiView.alpha = CGFloat(opacity)
}
}
struct Hintergrund: View {
var body: some View {
ZStack {
BlurView(style: .systemUltraThinMaterialLight, opacity: 0.7)
LinearGradient(gradient: Gradient(stops: [
.init(color: .white.opacity(0), location: 0),
.init(color: .white.opacity(0.1), location: 0.1),
.init(color: .white.opacity(0.5), location: 0.5),
.init(color: .white.opacity(0.5), location: 0.9), // Ändere die Position des letzten Haltepunkts
.init(color: .white.opacity(0), location: 1),
]), startPoint: .topLeading, endPoint: .bottomTrailing)
.cornerRadius(10)
.frame(maxWidth: .infinity, maxHeight: .infinity)
LinearGradient(gradient: Gradient(stops: [
.init(color: .white.opacity(0), location: 0),
.init(color: .white.opacity(0.1), location: 0.5),
.init(color: .white.opacity(0), location: 1),
]), startPoint: .topTrailing, endPoint: .bottomLeading)
.cornerRadius(10)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
}