【发布时间】:2020-05-10 20:49:23
【问题描述】:
我想制作一个可在 iOS 和 Mac 上跨平台运行的模式。
问题是,如果我快速切换模式,就会出现奇怪的行为。附加 GIF 与下面的奇怪行为。这是 SwiftUI 的错误吗?
如果不是,我做错了什么?
编辑:更多信息。 如果没有动画和过渡,交互会按预期进行。
这是 Playground 上的代码
import SwiftUI
import PlaygroundSupport
struct CView: View {
@State var isShown = false
var body: some View {
ZStack {
Color.white
ZStack {
Color.green
VStack {
HStack {
Spacer()
Text("Open").onTapGesture {
self.isShown = true
}
}
Spacer()
}
}
.edgesIgnoringSafeArea(.all)
.zIndex(0)
if self.isShown {
ZStack {
Color.red
VStack {
HStack {
Spacer()
Text("Close").onTapGesture {
self.isShown = false
}
}
Spacer()
}
}
.transition(AnyTransition.move(edge: .bottom))
.animation(.easeInOut)
.edgesIgnoringSafeArea(.all)
.zIndex(1)
}
}
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.setLiveView(CView())
``
[1]: https://i.stack.imgur.com/21z7z.gif
【问题讨论】: