     }
     
     func clipImage() -> (clipImage: UIImage, editRect: CGRect) {
-        let imageSize = self.editImage.size
-        let contentSize = self.scrollView.contentSize
-        let offset = self.scrollView.contentOffset
-        let insets = self.scrollView.contentInset
-        
-        var frame = CGRect.zero
-        frame.origin.x = floor((offset.x + insets.left) * (imageSize.width / contentSize.width))
-        frame.origin.x = max(0, frame.origin.x)
-        
-        frame.origin.y = floor((offset.y + insets.top) * (imageSize.height / contentSize.height))
-        frame.origin.y = max(0, frame.origin.y)
-        
-        frame.size.width = ceil(self.clipBoxFrame.width * (imageSize.width / contentSize.width))
-        frame.size.width = min(imageSize.width, frame.width)
-        
-        frame.size.height = ceil(self.clipBoxFrame.height * (imageSize.height / contentSize.height))
-        frame.size.height = min(imageSize.height, frame.height)
+        let frame = self.convertClipRectToEditImageRect()
         
         let origin = CGPoint(x: -frame.minX, y: -frame.minY)
         UIGraphicsBeginImageContextWithOptions(frame.size, false, self.editImage.scale)

        }
        let newImage = UIImage(cgImage: cgi, scale: self.editImage.scale, orientation: .up)
        return (newImage, frame)
    }
    
}

        animateImageView.frame = originFrame
        self.view.addSubview(animateImageView)
        
        // 将edit rect转换为相对edit image的rect
        let rect = convertClipRectToEditImageRect()
        // 旋转图片
        self.editImage = self.editImage.rotate(orientation: .left)
        // 将rect进行旋转，转换到相对于旋转后的edit image的rect
        self.editRect = CGRect(x: rect.minY, y: self.editImage.size.height-rect.minX-rect.width, width: rect.height, height: rect.width)
        self.scrollView.minimumZoomScale = 1
        self.scrollView.maximumZoomScale = 1
        self.scrollView.zoomScale = 1
        self.imageView.image = self.editImage
        self.layoutInitialImage()
        
        let toFrame = self.view.convert(self.containerView.frame, from: self.scrollView)
        let transform = CGAffineTransform(rotationAngle: -CGFloat.pi/2)
        self.overlayView.alpha = 0
        self.containerView.alpha = 0
        UIView.animate(withDuration: 0.3, animations: {
