Skip to content

Commit

Permalink
feat: support a new feature of fixing crop box when rotating 90 degree (
Browse files Browse the repository at this point in the history
#357)

* feat: support a new feature of fixing crop box when rotating 90 degree

add a new property "fixCropBoxWhenRotating90Degree" in CropViewConfig

* refactor: add rotatingCropBoxWhenRotatingImage90Degree and remove fixCropBoxWhenRotating90Degree

* refactor: rename rotatingCropBoxWhenRotatingImage90Degree to rotateCropBoxFor90DegreeRotation
  • Loading branch information
guoyingtao authored Nov 16, 2023
1 parent 6f73382 commit 5e125f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Sources/Mantis/CropView/CropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -903,15 +903,23 @@ extension CropView: CropViewProtocol {
}

func handleRotateAnimation() {
var rect = cropAuxiliaryIndicatorView.frame
rect.size.width = cropAuxiliaryIndicatorView.frame.height
rect.size.height = cropAuxiliaryIndicatorView.frame.width
if cropViewConfig.rotateCropBoxFor90DegreeRotation {
var rect = cropAuxiliaryIndicatorView.frame
rect.size.width = cropAuxiliaryIndicatorView.frame.height
rect.size.height = cropAuxiliaryIndicatorView.frame.width

let newRect = GeometryHelper.getInscribeRect(fromOutsideRect: getContentBounds(), andInsideRect: rect)
viewModel.cropBoxFrame = newRect
}

let newRect = GeometryHelper.getInscribeRect(fromOutsideRect: getContentBounds(), andInsideRect: rect)
viewModel.cropBoxFrame = newRect
let rotateAngle = newRotateType == .clockwise ? CGFloat.pi / 2 : -CGFloat.pi / 2
cropWorkbenchView.transform = cropWorkbenchView.transform.rotated(by: rotateAngle)
updatePositionFor90Rotation(by: rotateAngle + viewModel.radians)

if cropViewConfig.rotateCropBoxFor90DegreeRotation {
updatePositionFor90Rotation(by: rotateAngle + viewModel.radians)
} else {
adjustWorkbenchView(by: rotateAngle + viewModel.radians)
}
}

func handleRotateCompletion() {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Mantis/CropViewConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public struct CropViewConfig {

public var rotationControlViewHeight: CGFloat = 60

public var rotateCropBoxFor90DegreeRotation = true

var minimumCropBoxSize: CGFloat = 42

public var disableCropBoxDeformation = false
Expand Down

0 comments on commit 5e125f0

Please sign in to comment.