         case open
         case close
     }
-
-  // MARK: Life Cycle
-
+    
+    // MARK: Life Cycle
+    
     open override func awakeFromNib() {
         super.awakeFromNib()
-
+        
         commonInit()
     }
-
+    
     /**
      Call this method in methods init(style: UITableViewCellStyle, reuseIdentifier: String?) after creating Views
      */
     open func commonInit() {
         configureDefaultState()
-
+        
         selectionStyle = .none
-
+        
         containerView.layer.cornerRadius = foregroundView.layer.cornerRadius
         containerView.layer.masksToBounds = true
     }
-
+    
     // MARK: configure
-
+    
     func configureDefaultState() {
-
+        
         guard let foregroundViewTop = self.foregroundViewTop,
             let containerViewTop = self.containerViewTop else {
-            fatalError("set foregroundViewTop or containerViewTop outlets in storyboard")
-        }
-
+                fatalError("set foregroundViewTop or containerViewTop outlets in storyboard")
+        }
+        
         containerViewTop.constant = foregroundViewTop.constant
         containerView.alpha = 0
-
+        
         if let height = (foregroundView.constraints.filter { $0.firstAttribute == .height && $0.secondItem == nil }).first?.constant {
             foregroundView.layer.anchorPoint = CGPoint(x: 0.5, y: 1)
             foregroundViewTop.constant += height / 2
         }
         foregroundView.layer.transform = foregroundView.transform3d()
-
+        
         createAnimationView()
         contentView.bringSubview(toFront: foregroundView)
     }
-
+    
     func createAnimationItemView() -> [RotatedView] {
-        guard let animationView = self.animationView else {
-            fatalError()
-        }
-
+        
         var items = [RotatedView]()
         items.append(foregroundView)
         var rotatedViews = [RotatedView]()
-        for case let itemView as RotatedView in animationView.subviews.filter({ $0 is RotatedView }).sorted(by: { $0.tag < $1.tag }) {
-            rotatedViews.append(itemView)
-            if let backView = itemView.backView {
-                rotatedViews.append(backView)
-            }
-        }
+        
+        animationView?.subviews
+            .flatMap({ $0 as? RotatedView })
+            .sorted(by: { $0.tag < $1.tag })
+            .forEach { itemView in
+                rotatedViews.append(itemView)
+                if let backView = itemView.backView {
+                    rotatedViews.append(backView)
+                }
+        }
+        
         items.append(contentsOf: rotatedViews)
         return items
     }
-
+    
     func configureAnimationItems(_ animationType: AnimationType) {
-
+        
         guard let animationViewSuperView = animationView?.subviews else {
             fatalError()
         }
-
+        
         if animationType == .open {
             for view in animationViewSuperView.filter({ $0 is RotatedView }) {
                 view.alpha = 0

                               multiplier: 1, constant: 0),
            NSLayoutConstraint(item: view, attribute: .trailing, relatedBy: .equal, toItem: self, attribute: .trailing,
                               multiplier: 1, constant: 0),
        ])
    }
}

extension RotatedView: CAAnimationDelegate {

    func rotatedX(_ angle: CGFloat) {
        var allTransofrom = CATransform3DIdentity
        let rotateTransform = CATransform3DMakeRotation(angle, 1, 0, 0)

}

private extension UIView {
    
    func pb_takeSnapshot(_ frame: CGRect) -> UIImage? {
        UIGraphicsBeginImageContextWithOptions(frame.size, false, 0)
        
        guard let context = UIGraphicsGetCurrentContext() else { return nil }
        context.translateBy(x: frame.origin.x * -1, y: frame.origin.y * -1)
        
        layer.render(in: context)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        
        return image
    }
}
