swift - 为什么在 SwiftUI 中过渡结束后会应用 edgeIgnoringSafeArea 修饰符?
问题描述
我想用不透明度过渡覆盖 UIScreen。这是我的看法:
struct ContentView: View {
@State private var overlayUIScreen: Bool = false
var body: some View {
ZStack {
if overlayUIScreen {
Rectangle()
.edgesIgnoringSafeArea(.top)
.frame(width: UIScreen.main.bounds.size.width,
height: UIScreen.main.bounds.size.height)
.foregroundColor(Color.gray)
.transition(.opacity)
}
Button("Overlay?") {
withAnimation {
self.overlayUIScreen.toggle()
}
}
}
}
}
由于某种原因,安全区域在过渡完成后会改变颜色。
为什么会发生这种情况,我可以做些什么来解决这个问题?
解决方案
另一种解决方案是移动框架以修改ZStack
而不是Rectangle
struct ContentView: View {
@State private var overlayUIScreen: Bool = false
var body: some View {
ZStack {
if overlayUIScreen {
Rectangle()
.edgesIgnoringSafeArea(.top)
.foregroundColor(Color.gray)
.transition(.opacity)
}
Button("Overlay?") {
withAnimation {
self.overlayUIScreen.toggle()
}
}
}
.frame(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
}
}
推荐阅读
- c++ - 为什么我的程序对于大于 2^29 的数字会失败?
- reactjs - 当我单击页面上的任何元素时出现奇怪的容器。React/SCSS/React-Hook-Form
- python - 将字符串写入python文件中的特定位置
- javascript - Firebase - 使用 where 条件更新文档
- kubernetes-helm - 在 helm 图表中重用 uuid
- javascript - Apache ECharts - 用折线图范围选择画笔
- powershell - PowerShell - 如何从服务器列表中获取最新的 Windows 更新?数组/每个问题
- javascript - chart.js - 右侧标签的问题
- javascript - python3中的jQuery有问题
- r - 在 R 函数中重新映射因子水平,甚至更容易