Skip to content

Commit

Permalink
Calculate aspectFit scale and cancels it
Browse files Browse the repository at this point in the history
  • Loading branch information
djeni98 committed Jan 18, 2024
1 parent f405c57 commit 4f67671
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Virtual Crop/CropperEditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ struct CropperEditorView: View {
@State private var progressingScale: CGFloat = 1.0
@State private var progressingOffset = CGSize.zero

@State private var aspectFitImageSize = CGSize.zero
private var aspectFitScale: CGFloat {
aspectFitImageSize.width / uiimage.size.width
}

var dragGesture: some Gesture {
DragGesture()
.onChanged { value in
Expand All @@ -33,8 +38,18 @@ struct CropperEditorView: View {
var body: some View {
ZStack {
Image(uiImage: uiimage)
.resizable()
.background(
GeometryReader { g in
Color.gray.opacity(0).onAppear {
aspectFitImageSize = g.size
scale = scale / aspectFitScale
}
}
)
.scaleEffect(scale * progressingScale)
.offset(sum(offset, progressingOffset))
.aspectRatio(contentMode: .fit)
}
.gesture(dragGesture)
.simultaneousGesture(scaleGesture)
Expand Down

0 comments on commit 4f67671

Please sign in to comment.