ios - SwiftUI MultiviewResponder 神秘崩溃
问题描述
我遇到了这个我无法解释的崩溃,即使我将它归结为仍然会导致崩溃的最小组件:反复快速点击屏幕(使用两根手指)以隐藏/显示带有明确动画的覆盖按钮将在这个非常具体的布局下崩溃应用程序:
import SwiftUI
struct ContentView: View {
@State var showControls: Bool = true
var body: some View {
ZStack {
Rectangle().foregroundColor(Color.gray) // Removing this would fix it
VStack {
Text("someText")
Text("anotherText") // Removing this would also fix it
}
if showControls {
Text("Button")
.zIndex(1) // Removing this would also fix it
}
}
.onTapGesture {
withAnimation(.easeInOut(duration: 1)) { // Removing this would also fix it
showControls.toggle()
}
}
}
}
如代码注释中所述,这些更改中的任何一个都可以防止崩溃:
- 从 ZStack 底部移除 Rectangle
- 从 VStack 中删除两个视图之一
- 移除 zIndex (这将打破淡出动画)
- 移除显式动画调用
我想知道这里发生了什么,是什么导致了崩溃?
解决方案
推荐阅读
- docker - Gitlab docker 备份和恢复
- javascript - 需要帮助我对 discord.js 的取消静音命令
- vault - 使用 Vault.service 文件以开发模式启动 Vault Server
- python - 对 Dask 与 Pandas 进行基准测试时出现关键错误“负面评论”
- c# - 如何使用 Visual Studio 2019 中的控制台项目测试 .net 5 WPF 项目?
- javascript - 如何在 React 中动态映射另一个数组中的数组?
- python - 如何在不中断 python 中其他代码的情况下运行代码?
- regex - 正则表达式仅在单词不跟随另一个单词时才匹配单词
- apache-flink - flink 广播流和广播状态
- cython - ImportError:无法导入 Cython 模块