Skip to content

Commit

Permalink
Fix: fix the issue of manul crop not working sometime (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyingtao committed Apr 22, 2021
1 parent eacc8ed commit 6f58bb7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/Mantis/CropView/CropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ extension CropView {
}

func makeSureImageContainsCropOverlay() {
if !imageContainer.contains(rect: gridOverlayView.frame, fromView: self) {
if !imageContainer.contains(rect: gridOverlayView.frame, fromView: self, tolerance: 0.25) {
scrollView.zoomScaleToBound(animated: true)
}
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/Mantis/CropView/ImageContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ class ImageContainer: UIView {
imageView.frame = bounds
}

func contains(rect: CGRect, fromView view: UIView) -> Bool {
func contains(rect: CGRect, fromView view: UIView, tolerance: CGFloat = 1e-6) -> Bool {
let newRect = view.convert(rect, to: self)

let p1 = newRect.origin
let p2 = CGPoint(x: newRect.maxX, y: newRect.maxY)

let tolerance: CGFloat = 1e-6
let refBounds = bounds.insetBy(dx: -tolerance, dy: -tolerance)

return refBounds.contains(p1) && refBounds.contains(p2)
Expand Down

0 comments on commit 6f58bb7

Please sign in to comment.