【发布时间】:2021-04-21 08:34:53
【问题描述】:
我正在尝试实现此动画以在VStack 中插入元素,所有元素向下移动以为新元素创建空间,然后从右向左插入新元素。
下面的代码按照我的描述进行插入,但是如何使它也可以用于移除,动画应该类似,元素被完全移除(向右),然后其他元素向上移动)
struct ContentView: View {
@State var show = false
var body: some View {
VStack {
show ? Rectangle().frame(width: 100, height: 100, alignment: .center)
.animation(Animation.easeIn(duration: 0.5).delay(1))
.transition(.move(edge: .trailing)): nil
Rectangle().frame(width: 100, height: 100, alignment: .center)
Rectangle().frame(width: 100, height: 100, alignment: .center)
Rectangle().frame(width: 100, height: 100, alignment: .center)
Rectangle().frame(width: 100, height: 100, alignment: .center)
Button("Add") {
show.toggle()
}
Spacer()
}.animation(Animation.easeIn(duration: 0.5))
}
}
【问题讨论】:
标签: ios swift animation swiftui