31 lines
1017 B
Swift
31 lines
1017 B
Swift
import SwiftUI
|
||
import UIKit
|
||
|
||
// 通用毛玻璃效果视图(弱化强度)
|
||
struct VisualEffectView: UIViewRepresentable {
|
||
var effect: UIVisualEffect?
|
||
|
||
func makeUIView(context: Context) -> UIVisualEffectView {
|
||
let view = UIVisualEffectView(effect: nil)
|
||
|
||
let blurEffect = UIBlurEffect(style: .systemUltraThinMaterialLight)
|
||
let blurView = UIVisualEffectView(effect: blurEffect)
|
||
blurView.alpha = 0.3
|
||
|
||
let backgroundView = UIView()
|
||
backgroundView.backgroundColor = UIColor.white.withAlphaComponent(0.1)
|
||
backgroundView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||
|
||
view.contentView.addSubview(backgroundView)
|
||
view.contentView.addSubview(blurView)
|
||
blurView.frame = view.bounds
|
||
blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||
|
||
return view
|
||
}
|
||
|
||
func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
|
||
// 无需动态更新
|
||
}
|
||
}
|