我想模糊一个视图的背景,但不想闯入UIKit来完成它(例如UIVisualEffectView
).我正在翻文档,但什么都没有,似乎没有办法实时剪辑背景并对其应用效果.是我错了,还是我看错了?
我想模糊一个视图的背景,但不想闯入UIKit来完成它(例如UIVisualEffectView
).我正在翻文档,但什么都没有,似乎没有办法实时剪辑背景并对其应用效果.是我错了,还是我看错了?
只需在任何需要模糊的地方添加.blur()
个修改器,比如:
Image("BG")
.blur(radius: 20)
Note the top and bottom of the view
Note that你可以将Group
个视图模糊在一起.
您可以从UIKit中购买Perfict UIVisualEffectView
:
VisualEffectView(effect: UIBlurEffect(style: .dark))
有了这个小 struct :
struct VisualEffectView: UIViewRepresentable {
var effect: UIVisualEffect?
func makeUIView(context: UIViewRepresentableContext<Self>) -> UIVisualEffectView { UIVisualEffectView() }
func updateUIView(_ uiView: UIVisualEffectView, context: UIViewRepresentableContext<Self>) { uiView.effect = effect }
}
您可以使用带有单行代码的iOS预定义material :
.background(.ultraThinMaterial)