Skip to content

Commit

Permalink
Fix #75
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyingtao committed Nov 20, 2020
1 parent d808168 commit 5ac5c72
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Sources/Mantis/CropView/CropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ extension CropView {
self.viewModel.setRotatingStatus(by: angle)
}) {[weak self] _ in
guard let self = self else { return }
self.viewModel.rotateBy90()
rotateAngle < 0 ? self.viewModel.counterclockwiseRotateBy90() : self.viewModel.clockwiseRotateBy90()
self.viewModel.setBetweenOperationStatus()
completion()
}
Expand All @@ -660,7 +660,7 @@ extension CropView {
}) {[weak self] _ in
guard let self = self else { return }
self.scrollView.updateMinZoomScale()
self.viewModel.rotateBy90()
rotateAngle < 0 ? self.viewModel.counterclockwiseRotateBy90() : self.viewModel.clockwiseRotateBy90()
self.viewModel.setBetweenOperationStatus()
completion()
}
Expand Down
19 changes: 18 additions & 1 deletion Sources/Mantis/CropView/CropViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ enum ImageRotationType: CGFloat {
self = ImageRotationType(rawValue: self.rawValue - 90) ?? .none
}
}

mutating func clockwiseRotate90() {
switch (self) {
case .counterclockwise90:
self = .none
case .counterclockwise180:
self = .counterclockwise90
case .counterclockwise270:
self = .counterclockwise180
case .none:
self = .counterclockwise270
}
}
}

class CropViewModel: NSObject {
Expand Down Expand Up @@ -66,10 +79,14 @@ class CropViewModel: NSObject {
setInitialStatus()
}

func rotateBy90() {
func counterclockwiseRotateBy90() {
rotationType.counterclockwiseRotate90()
}

func clockwiseRotateBy90() {
rotationType.clockwiseRotate90()
}

func getTotalRadias(by radians: CGFloat) -> CGFloat {
return radians + rotationType.rawValue * CGFloat.pi / 180
}
Expand Down

0 comments on commit 5ac5c72

Please sign in to comment.