如何在过渡期间为子视图的相对偏移设置动画?在过渡期间为状态设置动画时,它似乎会覆盖过渡设置的位置。
struct ContentView: View {
@State var showPageTwo = false
var body: some View {
ZStack {
Button("Show page two") { showPageTwo = true }
if showPageTwo {
PageTwo() { showPageTwo = false }
.zIndex(1.0)
.animation(.linear(duration: 1))
.transition(.move(edge: .bottom))
}
}
}
}
struct PageTwo: View {
@State var buttonOffset: CGFloat = 200
let dismissAction: () -> Void
var body: some View {
ZStack {
Color.gray.edgesIgnoringSafeArea(.all)
Button("Dismiss", action: dismissAction)
.offset(x: buttonOffset, y: buttonOffset)
.animation(.easeIn)
.onAppear {
buttonOffset = 0
}
}
}
}