Skip to content
This repository was archived by the owner on Jul 1, 2022. It is now read-only.

Commit 0ceaf82

Browse files
committed
Fixed cropping issue when picture is zoomed
1 parent 848775c commit 0ceaf82

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

ALCameraViewController/ViewController/ConfirmViewController.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,17 @@ public class ConfirmViewController: UIViewController, UIScrollViewDelegate {
318318
y: cropOverlay.frame.origin.y + cropOverlay.outterGap,
319319
width: cropOverlay.frame.size.width - 2 * cropOverlay.outterGap,
320320
height: cropOverlay.frame.size.height - 2 * cropOverlay.outterGap)
321-
cropRect.origin.x += scrollView.contentOffset.x
322-
cropRect.origin.y += scrollView.contentOffset.y
323-
324-
let normalizedX = cropRect.origin.x / imageView.frame.width
325-
let normalizedY = cropRect.origin.y / imageView.frame.height
326-
327-
let normalizedWidth = cropRect.width / imageView.frame.width
328-
let normalizedHeight = cropRect.height / imageView.frame.height
321+
cropRect.origin.x += scrollView.contentOffset.x - imageView.frame.origin.x
322+
cropRect.origin.y += scrollView.contentOffset.y - imageView.frame.origin.y
323+
324+
let normalizedX = max(0, cropRect.origin.x / imageView.frame.width)
325+
let normalizedY = max(0, cropRect.origin.y / imageView.frame.height)
326+
327+
let extraWidth = min(0, cropRect.origin.x)
328+
let extraHeight = min(0, cropRect.origin.y)
329+
330+
let normalizedWidth = min(1, (cropRect.width + extraWidth) / imageView.frame.width)
331+
let normalizedHeight = min(1, (cropRect.height + extraHeight) / imageView.frame.height)
329332

330333
return CGRect(x: normalizedX, y: normalizedY, width: normalizedWidth, height: normalizedHeight)
331334
}

0 commit comments

Comments
 (0)