     
     for constraint in containerView.constraints { // added height constraint
       if constraint.firstAttribute == .height {
-        let newConstraint = NSLayoutConstraint(item: anAnimationView, attribute: constraint.firstAttribute,
+        let newConstraint = NSLayoutConstraint(item: animationView, attribute: constraint.firstAttribute,
           relatedBy: constraint.relation, toItem: nil, attribute: constraint.secondAttribute,
           multiplier: constraint.multiplier, constant: constraint.constant)
         
-        anAnimationView.addConstraint(newConstraint)
-      }
-    }
-    animationView = anAnimationView
+        animationView.addConstraint(newConstraint)
+      }
+    }
   }
 
   

    
    let firstItemView = animationView.subviews.filter{$0.tag == 0}.first
    
    if let first = firstItemView {
      first.layer.masksToBounds = true
      DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(durations[0] * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: { 
                first.layer.cornerRadius = 0
      })
    }
    DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: {
      self.animationView?.alpha = 0
      self.containerView.alpha  = 1

      hidden = !hidden
      delay += durations[index]
    }
    DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: {
      self.animationView?.alpha = 0
      completion?()
    })
    
    let firstItemView = animationView?.subviews.filter{$0.tag == 0}.first
    firstItemView?.layer.cornerRadius = 0
    firstItemView?.layer.masksToBounds = true
    if let durationFirst = durations.first {
      DispatchQueue.main.asyncAfter(deadline: .now() + delay - durationFirst * 2, execute: {
        firstItemView?.layer.cornerRadius = self.foregroundView.layer.cornerRadius
        firstItemView?.setNeedsDisplay()
        firstItemView?.setNeedsLayout()
      })
    }
  }
}


// MARK: RotatedView
open class RotatedView: UIView {
  var hiddenAfterAnimation = false
  var backView: RotatedView?
