fix: Dragging after rotation(#1), adjust to fill after rotation, animation.

This commit is contained in:
Shibo Lyu 2023-09-01 11:32:29 +08:00
parent 63a60f802a
commit e703e25200
2 changed files with 13 additions and 6 deletions

View file

@ -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: {

View file

@ -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()
}
}
}