gpt4 book ai didi

ios - 有没有办法设置 fullScreenCover 背景不透明度?

转载 作者:行者123 更新时间:2023-12-04 02:29:15 32 4
gpt4 key购买 nike

我需要从 View 组件内的按钮推送模态视图,但应该只覆盖屏幕高度的下半部分,上半部分是半透明背景(不透明度为 30% 的黑色)。在 fullscreenCover View 构建器中设置最顶层 View 的不透明度不起作用。任何帮助,将不胜感激。

struct ContentView: View {

@State var present: Bool = false
var body: some View {

VStack(spacing: 20) {

Button(action: {
present = true
}, label: {

Text("spawn translucent modal")
})
.fullScreenCover(isPresented: $present) {
VStack(spacing: 20) {
Spacer()
.frame(maxWidth: .infinity, minHeight: 100)
.background(Color.black)
.opacity(0.3)

Text("modal")
}
.background(Color.clear)

}

Text("some content")
Text("some more content")
}
}
}

最佳答案

这是可能的解决方案

        .fullScreenCover(isPresented: $present) {
VStack(spacing: 20) {
Spacer()
.frame(maxWidth: .infinity, minHeight: 100)
.background(Color.black)
.opacity(0.3)

Text("modal")
}
.background(BackgroundCleanerView()) // << helper !!
}
现在是 helper
struct BackgroundCleanerView: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
let view = UIView()
DispatchQueue.main.async {
view.superview?.superview?.backgroundColor = .clear
}
return view
}

func updateUIView(_ uiView: UIView, context: Context) {}
}

关于ios - 有没有办法设置 fullScreenCover 背景不透明度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65295388/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com