                 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")

            // decrease containerView height or increase itemCount
            assert(containerViewSize.height - 2 * foregroundViewSize.height >= itemHeight, "contanerView.height too high")
        }

        var yPosition = 2 * foregroundViewSize.height
        var tag = 2
        for _ in 2 ..< itemCount {
            image = containerView.pb_takeSnapshot(CGRect(x: 0, y: yPosition, width: containerViewSize.width, height: itemHeight))

            imageView = UIImageView(image: image)
            let rotatedView = RotatedView(frame: imageView.frame)

            rotatedView.addSubview(imageView)
            rotatedView.layer.anchorPoint = CGPoint(x: 0.5, y: 0)
            rotatedView.layer.transform = rotatedView.transform3d()
            animationView?.addSubview(rotatedView)
            rotatedView.frame = CGRect(x: 0, y: yPosition, width: rotatedView.bounds.size.width, height: itemHeight)
            rotatedView.tag = tag

            yPosition += itemHeight
            tag += 1
        }

        containerView.alpha = 0

        if let animationView = self.animationView {
            // added back view
            var previuosView: RotatedView?
            for case let container as RotatedView in animationView.subviews.sorted(by: { $0.tag < $1.tag })
                where container.tag > 0 && container.tag < animationView.subviews.count {
                previuosView?.addBackView(container.bounds.size.height, color: backViewColor)
                previuosView = container
            }
        }
        animationItemViews = createAnimationItemView()
    }

    fileprivate func removeImageItemsFromAnimationView() {

        guard let animationView = self.animationView else {
            return
        }

        animationView.subviews.forEach({ $0.removeFromSuperview() })
    }

    // MARK: public

    /// Unfold cell.
    ///
    /// - Parameters:

            containerView.alpha = value ? 1 : 0
        }
    }
    
    open func isAnimating() -> Bool {
        return animationView?.alpha == 1 ? true : false
    }
    
    open var isUnfolded = false
    
    // MARK: Animations
    
    open func animationDuration(_ itemIndex: NSInteger, type: AnimationType) -> TimeInterval {
        return type == .close ? durationsForCollapsedState[itemIndex] : durationsForExpandedState[itemIndex]
    }
    
    open var durationsForExpandedState: [TimeInterval] = []
    open var durationsForCollapsedState: [TimeInterval] = []
    
    func durationSequence(_ type: AnimationType) -> [TimeInterval] {
        var durations = [TimeInterval]()
        for i in 0 ..< itemCount - 1 {
