所以从技术上讲,我想显示一个加载屏幕 View 。我正在使用 fullScreenCover
.
struct ContentView: View {
@State private var isLoading = false
var body: some View {
VStack {
Text("Hello there")
Button("Start loading") {
isLoading.toggle()
}
.fullScreenCover(isPresented: $isLoading) {
ZStack{
Color.black.opacity(0.5).edgesIgnoringSafeArea(.all)
VStack {
ProgressView()
Button("Stop loading") {
isLoading.toggle()
}
}
}
}
}
}
}
问题是我不能使这个加载屏幕半透明。 sheet
或 popover
行为方式相同。
最佳答案
这是可能方式的演示。您可以根据需要调整视觉效果参数。
使用 Xcode 12/iOS 14 测试。
// ... other code
.fullScreenCover(isPresented: $isLoading) {
ZStack{
Color.black.opacity(0.5).edgesIgnoringSafeArea(.all)
VStack {
ProgressView()
Button("Stop loading") {
isLoading.toggle()
}
}
}
.background(BackgroundBlurView())
}
}
}
}
struct BackgroundBlurView: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
let view = UIVisualEffectView(effect: UIBlurEffect(style: .light))
DispatchQueue.main.async {
view.superview?.superview?.backgroundColor = .clear
}
return view
}
func updateUIView(_ uiView: UIView, context: Context) {}
}
backup
关于ios - SwiftUI:fullScreenCover 的半透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64301041/