In the simple example below, RainbowView is presented when the @Published variable "settings.showRainbow" is true.
The RainbowView sets "settings.showRainbow" to false when the user taps one of the colours of the rainbow, which causes the parent view to remove it, and display another view. The tap location is also set by RainbowView.
When RainbowView is removed, its removal transition animation is to zoom in around the location where the user tapped.
It works perfectly ... except, of course, that the value of the removal transition's .scale anchor, the variable "tapLocation", is set when the view is presented, rather than when it is removed.
What I'd like, is for SwiftUI to wait to capture the anchor location until the point in time where the view is about to be removed.
Does anyone know if this is possible? I could make the child view responsible for animating itself when it's about to be dismissed (which works OK), but I would prefer to have the parent view be responsible for the removal animation.
Here's a code snippet:
if settings.showRainbow {
RainbowView()
.transition(AnyTransition
.asymmetric(
insertion: .opacity,
removal: .scale(scale: 24,
anchor: tapLocation)))
} else {
OtherView()
0 comments:
Post a Comment
Thanks