diff --git a/Sources/CropImage/DefaultControlsView.swift b/Sources/CropImage/DefaultControlsView.swift index ff35908..4b69e89 100644 --- a/Sources/CropImage/DefaultControlsView.swift +++ b/Sources/CropImage/DefaultControlsView.swift @@ -19,7 +19,7 @@ public struct DefaultControlsView: View { var rotateButton: some View { Button { let roundedAngle = Angle.degrees((rotation.degrees / 90).rounded() * 90) - withAnimation { + withAnimation(.interactiveSpring()) { rotation = roundedAngle + .degrees(90) } } label: { diff --git a/Sources/CropImage/UnderlyingImageView.swift b/Sources/CropImage/UnderlyingImageView.swift index 346c8eb..7166bf4 100644 --- a/Sources/CropImage/UnderlyingImageView.swift +++ b/Sources/CropImage/UnderlyingImageView.swift @@ -66,7 +66,7 @@ struct UnderlyingImageView: View { clampedOffset.height = clampedOffset.height.clamped(to: yOffsetBounds(at: clampedScale)) if clampedScale != scale || clampedOffset != offset { - withAnimation { + withAnimation(.interactiveSpring()) { scale = clampedScale offset = clampedOffset } @@ -104,7 +104,6 @@ struct UnderlyingImageView: View { .onEnded { value in offset = offset + tempOffset tempOffset = .zero - adjustToFulfillTargetFrame() } } @@ -116,7 +115,6 @@ struct UnderlyingImageView: View { .onEnded { value in scale = scale * tempScale tempScale = 1 - adjustToFulfillTargetFrame() } } @@ -133,14 +131,23 @@ struct UnderlyingImageView: View { var body: some View { imageView + .rotationEffect(rotation + tempRotation) .scaleEffect(scale * tempScale) .offset(offset + tempOffset) - .rotationEffect(rotation + tempRotation) .overlay(interactionView) + .clipped() .onChange(of: viewSize) { newValue in setInitialScale(basedOn: newValue) } - .clipped() + .onChange(of: scale) { _ in + adjustToFulfillTargetFrame() + } + .onChange(of: offset) { _ in + adjustToFulfillTargetFrame() + } + .onChange(of: rotation) { _ in + adjustToFulfillTargetFrame() + } } }