mirror of
https://github.com/laosb/CropImage.git
synced 2025-04-30 23:51:08 +00:00
fix: Dragging after rotation(#1), adjust to fill after rotation, animation.
This commit is contained in:
parent
63a60f802a
commit
e703e25200
2 changed files with 13 additions and 6 deletions
|
@ -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: {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue