Git Product home page Git Product logo

Comments (1)

qchenqizhi avatar qchenqizhi commented on August 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.