I am struggling with the animation of views when inserting them into a stack. In general, I am trying to create an effect where cards fly out from the stack and move to their final destination. I have tried many options with built-in transitions, but I still cannot achieve the desired result.
Maybe there is another way to solve this problem so the animation would look more natural? All the user needs to do is press the stack and the card will fly out of the stack exactly (the center of the stack is should be a starting point of animation). It would be better to fly it directly to its final destination (I know the final cards' amount at the very beginning, so I can clearly see when all the cards have been placed, when all of them appear on the screen).
Now it looks strange and unnaturalЖ

Here is the code snippet, but I guess it is not very helpful
VStack {
HStack {
if viewModel.firstCardShown {
RotatableCardView(cardLayout: viewModel.firstCardLayout, width: cardWidth - 20, isFlipped: $isFirstCardFlipped)
.transition(.move(edge: .bottom))
}
if viewModel.secondCardShown {
RotatableCardView(cardLayout: viewModel.secondCardLayout, width: cardWidth - 20, isFlipped: $isSecondCardFlipped)
.transition(.move(edge: .bottom))
}
if viewModel.thirdCardShown {
RotatableCardView(cardLayout: viewModel.thirdCardLayout, width: cardWidth - 20, isFlipped: $isThirdCardFlipped)
.transition(.move(edge: .bottom))
}
}
.padding(.top, 40)
.containerRelativeFrame(.vertical) { height, _ in
height / 2
}
CardsDeckView()
.onTapGesture(perform: {
withAnimation(.easeIn(duration: 0.6)) {
if !viewModel.firstCardShown {
viewModel.firstCardShown.toggle()
} else if !viewModel.secondCardShown {
viewModel.secondCardShown.toggle()
} else if !viewModel.thirdCardShown {
viewModel.thirdCardShown.toggle()
}
}
})
.containerRelativeFrame(.vertical) { height, _ in
height / 2
}
