                 let newConstraint = NSLayoutConstraint(item: animationView, attribute: constraint.firstAttribute,
                                                        relatedBy: constraint.relation, toItem: constraint.secondItem, attribute: constraint.secondAttribute,
                                                        multiplier: constraint.multiplier, constant: constraint.constant)
-
+                
                 newConstraints.append(newConstraint)
             } else if let firstItem = constraint.firstItem as? UIView, let secondItem: UIView = constraint.secondItem as? UIView, secondItem == containerView {
                 let newConstraint = NSLayoutConstraint(item: firstItem, attribute: constraint.firstAttribute,
                                                        relatedBy: constraint.relation, toItem: animationView, attribute: constraint.secondAttribute,
                                                        multiplier: constraint.multiplier, constant: constraint.constant)
-
+                
                 newConstraints.append(newConstraint)
             }
         }
         self.contentView.addConstraints(newConstraints)
-
+        
         for constraint in containerView.constraints { // added height constraint
             if constraint.firstAttribute == .height, let item: UIView = constraint.firstItem as? UIView, item == containerView {
                 let newConstraint = NSLayoutConstraint(item: animationView, attribute: constraint.firstAttribute,
                                                        relatedBy: constraint.relation, toItem: nil, attribute: constraint.secondAttribute,
                                                        multiplier: constraint.multiplier, constant: constraint.constant)
-
+                
                 animationView.addConstraint(newConstraint)
             }
         }
     }
-
+    
     func addImageItemsToAnimationView() {
         containerView.alpha = 1
         let containerViewSize = containerView.bounds.size
         let foregroundViewSize = foregroundView.bounds.size
-
+        
         // added first item
         var image = containerView.pb_takeSnapshot(CGRect(x: 0, y: 0, width: containerViewSize.width, height: foregroundViewSize.height))
         var imageView = UIImageView(image: image)
         imageView.tag = 0
         imageView.layer.cornerRadius = foregroundView.layer.cornerRadius
         animationView?.addSubview(imageView)
-
+        
         // added secod item
         image = containerView.pb_takeSnapshot(CGRect(x: 0, y: foregroundViewSize.height, width: containerViewSize.width, height: foregroundViewSize.height))
-
+        
         imageView = UIImageView(image: image)
         let rotatedView = RotatedView(frame: imageView.frame)
         rotatedView.tag = 1
         rotatedView.layer.anchorPoint = CGPoint(x: 0.5, y: 0)
         rotatedView.layer.transform = rotatedView.transform3d()
-
+        
         rotatedView.addSubview(imageView)
         animationView?.addSubview(rotatedView)
         rotatedView.frame = CGRect(x: imageView.frame.origin.x, y: foregroundViewSize.height, width: containerViewSize.width, height: foregroundViewSize.height)
-
+        
         // added other views
         let itemHeight = (containerViewSize.height - 2 * foregroundViewSize.height) / CGFloat(itemCount - 2)
-
+        
         if itemCount == 2 {
             // decrease containerView height or increase itemCount
             assert(containerViewSize.height - 2 * foregroundViewSize.height == 0, "contanerView.height too high")

        allTransofrom = CATransform3DConcat(allTransofrom, transform3d())
        self.layer.transform = allTransofrom
    }

    func transform3d() -> CATransform3D {
        var transform = CATransform3DIdentity
        transform.m34 = 2.5 / -2000
        return transform
    }

    // MARK: animations

    func foldingAnimation(_ timing: String, from: CGFloat, to: CGFloat, duration: TimeInterval, delay: TimeInterval, hidden: Bool) {

        let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation.x")
        rotateAnimation.timingFunction = CAMediaTimingFunction(name: timing)
        rotateAnimation.fromValue = from

            }
        }
    }
    
    func createAnimationView() {
        animationView = UIView(frame: containerView.frame)
        animationView?.layer.cornerRadius = foregroundView.layer.cornerRadius
        animationView?.backgroundColor = .clear
        animationView?.translatesAutoresizingMaskIntoConstraints = false
        animationView?.alpha = 0
        
        guard let animationView = self.animationView else { return }
        
        self.contentView.addSubview(animationView)
        
        // copy constraints from containerView
        var newConstraints = [NSLayoutConstraint]()
        for constraint in self.contentView.constraints {
