Skip to content

Commit

Permalink
fix: allow set different fixed ratio after preset transforamtion (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyingtao committed Apr 26, 2021
1 parent c5a7891 commit 06e98b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Sources/Mantis/CropView/CropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,9 @@ extension CropView {
}


func setFixedRatioCropBox(zoom: Bool = true) {
viewModel.setCropBoxFrame(by: getInitialCropBoxRect(), and: getImageRatioH())
func setFixedRatioCropBox(zoom: Bool = true, cropBox: CGRect? = nil) {
let refCropBox = cropBox ?? getInitialCropBoxRect()
viewModel.setCropBoxFrame(by: refCropBox, and: getImageRatioH())

let contentRect = getContentBounds()
adjustUIForNewCrop(contentRect: contentRect, animation: false, zoom: zoom) { [weak self] in
Expand Down
11 changes: 9 additions & 2 deletions Sources/Mantis/CropViewController/CropViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,16 @@ public class CropViewController: UIViewController {
super.viewDidAppear(animated)
processPresetTransformation() { [weak self] transform in
guard let self = self else { return }
if case .alwaysUsingOnePresetFixedRatio = self.config.presetFixedRatioType {
if case .alwaysUsingOnePresetFixedRatio(let ratio) = self.config.presetFixedRatioType {
self.cropView.aspectRatioLockEnabled = true
self.cropView.viewModel.aspectRatio = transform.maskFrame.width / transform.maskFrame.height
self.cropToolbar.handleFixedRatioSetted(ratio: ratio)

if ratio == 0 {
self.cropView.viewModel.aspectRatio = transform.maskFrame.width / transform.maskFrame.height
} else {
self.cropView.viewModel.aspectRatio = CGFloat(ratio)
self.cropView.setFixedRatioCropBox(zoom: false, cropBox: cropView.viewModel.cropBoxFrame)
}
}
}
}
Expand Down

0 comments on commit 06e98b8

Please sign in to comment.