Comments (1)
This requirement is not very common, so I will not add it to the library, you need to modify the source code to implement your needs.
First, you need to modify the cropBoxFrame
calculation in rotate90degrees(clockwise: Bool = true)
and add matchScrollViewAndCropView
or something similar after the rotation.
Then, remove the animation related to rotatingOverlay
and overlay
An attempt that has not been fully tested:
diff --git a/QCropper/Core/CropperProtocols/Rotatable.swift b/QCropper/Core/CropperProtocols/Rotatable.swift
index 7428df5..a215768 100644
--- a/QCropper/Core/CropperProtocols/Rotatable.swift
+++ b/QCropper/Core/CropperProtocols/Rotatable.swift
@@ -53,26 +53,6 @@ extension Rotatable where Self: CropperViewController {
topBar.isUserInteractionEnabled = false
bottomView.isUserInteractionEnabled = false
- guard let animationContainer = scrollView.superview else { return }
-
- // Make sure to cover the entire screen while rotating
- let scale = max(maxCropRegion.size.width / overlay.cropBoxFrame.size.width, maxCropRegion.size.height / overlay.cropBoxFrame.size.height)
- let frame = animationContainer.bounds.insetBy(dx: -animationContainer.width * scale * 3, dy: -animationContainer.height * scale * 3)
-
- let rotatingOverlay = Overlay(frame: frame)
- rotatingOverlay.blur = false
- rotatingOverlay.maskColor = backgroundView.backgroundColor ?? .black
- rotatingOverlay.cropBoxAlpha = 0
- animationContainer.addSubview(rotatingOverlay)
-
- let rotatingCropBoxFrame = rotatingOverlay.convert(overlay.cropBoxFrame, from: backgroundView)
- rotatingOverlay.cropBoxFrame = rotatingCropBoxFrame
- rotatingOverlay.transform = .identity
- rotatingOverlay.layer.anchorPoint = CGPoint(x: rotatingCropBoxFrame.midX / rotatingOverlay.size.width,
- y: rotatingCropBoxFrame.midY / rotatingOverlay.size.height)
-
- overlay.isHidden = true
-
UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
// rotate scroll view
if clockwise {
@@ -89,22 +69,19 @@ extension Rotatable where Self: CropperViewController {
let r = self.overlay.cropBoxFrame
var rect: CGRect = .zero
- let scaleX = self.maxCropRegion.size.width / r.size.height
- let scaleY = self.maxCropRegion.size.height / r.size.width
+ let scaleX = self.maxCropRegion.size.width / r.size.width
+ let scaleY = self.maxCropRegion.size.height / r.size.height
let scale = min(scaleX, scaleY)
- rect.size.width = r.size.height * scale
- rect.size.height = r.size.width * scale
+ rect.size.width = r.size.width * scale
+ rect.size.height = r.size.height * scale
rect.origin.x = cropBoxCenter.x - rect.size.width / 2.0
rect.origin.y = cropBoxCenter.y - rect.size.height / 2.0
self.overlay.cropBoxFrame = rect
- rotatingOverlay.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2.0).scaledBy(x: scale, y: scale)
- rotatingOverlay.center = scrollViewCenter
-
let rotatedRect = rect.applying(CGAffineTransform(rotationAngle: self.totalAngle))
let width = rotatedRect.size.width
let height = rotatedRect.size.height
@@ -121,21 +98,11 @@ extension Rotatable where Self: CropperViewController {
y: showingContentNormalizedCenter.y * self.imageView.height - self.scrollView.bounds.size.height * 0.5)
self.scrollView.contentOffset = self.safeContentOffsetForScrollView(newContentOffset)
self.scrollView.center = scrollViewCenter
+ self.matchScrollViewAndCropView()
}, completion: { _ in
- self.aspectRatioPicker.rotateAspectRatios()
- self.overlay.cropBoxAlpha = 0
- self.overlay.blur = true
- self.overlay.isHidden = false
- UIView.animate(withDuration: 0.25, animations: {
- rotatingOverlay.alpha = 0
- self.overlay.cropBoxAlpha = 1
- }, completion: { _ in
- rotatingOverlay.isHidden = true
- rotatingOverlay.removeFromSuperview()
- self.topBar.isUserInteractionEnabled = true
- self.bottomView.isUserInteractionEnabled = true
- self.updateButtons()
- })
+ self.topBar.isUserInteractionEnabled = true
+ self.bottomView.isUserInteractionEnabled = true
+ self.updateButtons()
})
}
}
from qcropper.
Related Issues (20)
- Is QCropper compatible for adding rotation gesture to rotate the image using fingers instead of buttons? HOT 1
- How can I crop the image using CIImage HOT 2
- Image blur after crop HOT 1
- force image crop HOT 4
- take photo from camera HOT 1
- originalImage.cropped(withCropperState: state) returns original image HOT 1
- Minimum Ios version HOT 1
- How to use QCropper with SwiftUI HOT 1
- Circular Cropper is not working HOT 1
- Image pick from camera displaying black
- Image flipping HOT 1
- cropbox dimensions HOT 1
- Quality degrades heavily when an image is cropped HOT 1
- Cannot re-edit result image
- How can I get pure cropRect without image like ToCropViewController HOT 1
- Does not crops when tried with screenshot images HOT 2
- How can custom the toolbar? Would you help me to do this feature? Many thanks! HOT 3
- I don't find the properties to set aspect ratio like the above image in our lib. Could you help me? HOT 5
- SeiftUI HOT 2
- Flip Doesnโt Work Second time with initialState. HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qcropper.