我有问题动画在SwiftUI,如果我使用.animation我的动画不工作.
ZStack(alignment: .bottom) {
VStack {
Button("Button") {
showView.toggle()
}
Spacer()
}
if showView {
RoundedRectangle(cornerRadius: 30)
.frame(height: UIScreen.main.bounds.height * 0.5)
.transition(.move(edge: .bottom))
.animation(.easeInOut, value: showView)
}
}
.ignoresSafeArea(edges: .bottom)
但是,如果我在我的按钮中使用了with Animation,并且删除了.Animation或保留它,它就可以工作了.
ZStack(alignment: .bottom) {
VStack {
Button("Button") {
withAnimation {
showView.toggle()
}
}
Spacer()
}
if showView {
RoundedRectangle(cornerRadius: 30)
.frame(height: UIScreen.main.bounds.height * 0.5)
.transition(.move(edge: .bottom))
.animation(.easeInOut, value: showView)
}
}
.ignoresSafeArea(edges: .bottom)
有人能给我解释一下这是怎么用的吗?我正在try DispatchQueue.main.async,它仍然是一样的.