When I add a drag gesture to dismiss my "big view" it scales to the amount of the gesture but if it dismisses, the view jumps to its origin scale and animates the view to the "small view".
Here is my example Code: ` struct TestView: View { @State var showBigView = false
@Namespace private var animationNameSpace
@State var gestureOffset: CGSize = .zero
var body: some View {
ZStack {
if !showBigView {
Image(systemName: "tshirt")
.resizable()
.scaledToFit()
.foregroundColor(.red)
.matchedGeometryEffect(id: "circel", in: animationNameSpace)
.transition(.scale(scale: 1))
.frame(width: 100, height: 100)
.onTapGesture {
withAnimation {
showBigView = true
}
}
} else {
Image(systemName: "tshirt")
.resizable()
.scaledToFit()
.foregroundColor(.red)
.matchedGeometryEffect(id: "circel", in: animationNameSpace)
.transition(.scale(scale: 1))
.frame(width: 300, height: 300)
.scaleEffect(abs(gestureOffset.height / 1000 - 1))
.gesture(DragGesture().onChanged {
guard $0.translation.height > 0 else { return }
self.gestureOffset = $0.translation
if abs($0.translation.height) > 150 {
withAnimation {
showBigView = false
gestureOffset = .zero
}
}
})
}
}
}
} `
It should not jump when the view dismisses with a specific scaleEffect.
I believe you're trying to:
This approach works:
It's not necessary to create two separate images and synchronize them with
matchedGeometryEffect
. Instead, you can use your@State
boolean to control whether or not gestures have any effect.