Skip to content

Commit

Permalink
fix: fix “keep zooming” issue (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyingtao committed Apr 22, 2021
1 parent 7a2b875 commit eacc8ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 8 additions & 5 deletions Sources/Mantis/CropView/CropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ extension CropView {

func adjustUIForNewCrop(contentRect:CGRect,
animation: Bool = true,
zoom: Bool = true,
completion: @escaping ()->Void) {

let scaleX: CGFloat
Expand Down Expand Up @@ -467,9 +468,11 @@ extension CropView {
func updateUI(by newCropBoxFrame: CGRect, and scaleFrame: CGRect) {
viewModel.cropBoxFrame = newCropBoxFrame

let zoomRect = convert(scaleFrame,
to: scrollView.imageContainer)
scrollView.zoom(to: zoomRect, animated: false)
if zoom {
let zoomRect = convert(scaleFrame,
to: scrollView.imageContainer)
scrollView.zoom(to: zoomRect, animated: false)
}
scrollView.checkContentOffset()
makeSureImageContainsCropOverlay()
}
Expand Down Expand Up @@ -693,12 +696,12 @@ extension CropView {
rotationDial?.rotateDialPlate(to: CGAngle(radians: radians), animated: false)
}

func setFixedRatioCropBox() {
func setFixedRatioCropBox(zoom: Bool = true) {
viewModel.setCropBoxFrame(by: getInitialCropBoxRect(),
and: getImageRatioH())

let contentRect = getContentBounds()
adjustUIForNewCrop(contentRect: contentRect, animation: false) { [weak self] in
adjustUIForNewCrop(contentRect: contentRect, animation: false, zoom: zoom) { [weak self] in
guard let self = self else { return }
if self.forceFixedRatio {
self.imageStatusChangedCheckForForceFixedRatio = true
Expand Down
8 changes: 4 additions & 4 deletions Sources/Mantis/CropViewController/CropViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,18 @@ public class CropViewController: UIViewController {
}


func setFixedRatio(_ ratio: Double) {
private func setFixedRatio(_ ratio: Double, zoom: Bool = true) {
cropToolbar.handleFixedRatioSetted(ratio: ratio)
cropView.aspectRatioLockEnabled = true

if (cropView.viewModel.aspectRatio != CGFloat(ratio)) {
cropView.viewModel.aspectRatio = CGFloat(ratio)

if case .alwaysUsingOnePresetFixedRatio = config.presetFixedRatioType {
self.cropView.setFixedRatioCropBox()
self.cropView.setFixedRatioCropBox(zoom: zoom)
} else {
UIView.animate(withDuration: 0.5) {
self.cropView.setFixedRatioCropBox()
self.cropView.setFixedRatioCropBox(zoom: zoom)
}
}

Expand Down Expand Up @@ -386,7 +386,7 @@ public class CropViewController: UIViewController {
ratios: fixedRatioManager.ratios,
fixRatiosShowType: config.cropToolbarConfig.fixRatiosShowType)
ratioPresenter?.didGetRatio = {[weak self] ratio in
self?.setFixedRatio(ratio)
self?.setFixedRatio(ratio, zoom: false)
}
ratioPresenter?.present(by: self, in: presentSourceView)
}
Expand Down

0 comments on commit eacc8ed

Please sign in to comment.