I would like to trigger an animation when the user drags a finger over my view.
I can do something like
Image(…)
.rotationEffect(…)
.animation(self.isAnimating ? .spring : .default)
.gesture(
DragGesture(minimumDistance: 5, coordinateSpace: .global)
.onChanged { value in
self.isAnimating = true
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.isAnimating = false
}
}
)
However that captures only a drag event that started over the image. A drag event that started elsewhere and then travels over the image is ignored.
I can also detect the drag events in the parent view and calculate which of the child views is being dragged over – and that's fine. However, how do I tell the child view to animate then? Updating their properties causes a re-render which of course cancels the animation.
Passing ui data like this through a model seems like an anti pattern.
Any suggestions?

