I am trying to do a simple matchedGeometryEffect and it's not working. I've got a simple Image that has a fixed frame and I want to animate it to an Image that takes up the whole screen. This is how it looks like right now, as you can see, it doesn't transition smoothly:
This is my code:
struct ContentView: View {
@State private var enlarged = false
@Namespace private var animation
var body: some View {
ZStack {
if (enlarged) {
Image("dunes")
.resizable()
.aspectRatio(contentMode: .fill)
.matchedGeometryEffect(id: "image", in: animation)
.ignoresSafeArea(.all, edges: .all)
} else {
Image("dunes")
.resizable()
.aspectRatio(contentMode: .fill)
.matchedGeometryEffect(id: "image", in: animation)
.frame(width: 300, height: 225)
}
}
.onTapGesture {
withAnimation {
enlarged.toggle()
}
}
}
}
