         
         let alpha: CGFloat = 0.1
         let offScreenBottom = CGAffineTransformMakeTranslation(0, container.frame.height)
-
-        // Prepare header
+        
         let headerTo = (toController as! MCMHeaderAnimatedDelegate).headerView()
         let headerFrom = (fromController as! MCMHeaderAnimatedDelegate).headerView()
         
-        if self.transitionMode == .Present {
-            self.headerToFrame = headerTo.superview!.convertRect(headerTo.frame, toView: nil)
-            self.headerFromFrame = headerFrom.superview!.convertRect(headerFrom.frame, toView: nil)
+        if mode == .Present {
+            headerToFrame = headerTo.superview!.convertRect(headerTo.frame, toView: nil)
+            headerFromFrame = headerFrom.superview!.convertRect(headerFrom.frame, toView: nil)
         }
         
         headerFrom.alpha = 0
         headerTo.alpha = 0
         let headerIntermediate = (fromController as! MCMHeaderAnimatedDelegate).headerCopy(headerFrom)
-        headerIntermediate.frame = self.transitionMode == .Present ? self.headerFromFrame : self.headerToFrame
+        headerIntermediate.frame = mode == .Present ? headerFromFrame : headerToFrame
         
-        if self.transitionMode == .Present {
+        if mode == .Present {
             toView.transform = offScreenBottom
-            
             container.addSubview(fromView)
             container.addSubview(toView)
             container.addSubview(headerIntermediate)

                toView.alpha = 1.0
                headerIntermediate.frame = self.headerFromFrame
            }
            
            }, completion: { finished in
                
                headerIntermediate.removeFromSuperview()
                headerTo.alpha = 1
                headerFrom.alpha = 1
                
                transitionContext.completeTransition(true)
                
        })
        
    }
    
}

extension MCMHeaderAnimated: UIViewControllerInteractiveTransitioning {
    
    public override func startInteractiveTransition(transitionContext: UIViewControllerContextTransitioning) {
        super.startInteractiveTransition(transitionContext)
    }

}

extension MCMHeaderAnimated: UIViewControllerTransitioningDelegate {

    public func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        
        self.transitionMode = .Present
        return self
    }

    public func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        
        self.transitionMode = .Dismiss
        return self
        
    }
    
    public func interactionControllerForDismissal(animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
        return self.transitionInteracted ? self : nil
    }
    
}
public protocol MCMHeaderAnimatedDelegate {
    
    func headerView() -> UIView
    func headerCopy(subview: UIView) -> UIView
    
}

public class MCMHeaderAnimated: UIPercentDrivenInteractiveTransition {
    
    public enum TransitionMode: Int {
        case Present, Dismiss
    }
    
    public var mode: TransitionMode = .Present
    
    private var interactive = false
    
    private let panGesture = UIPanGestureRecognizer()
    
    public var destinationViewController: UIViewController? {
        didSet {
            panGesture.addTarget(self, action: "handlePan:")
            destinationViewController?.view.addGestureRecognizer(panGesture)
        }
    }
    
    private var headerToFrame = CGRect()
    private var headerFromFrame = CGRect()
    
    // MARK:
    
    func handlePan(recognizer: UIPanGestureRecognizer) {
        if let
            destinationViewController = destinationViewController,
            view = recognizer.view
        {
            let translation = recognizer.translationInView(view)
            let delta = translation.y / view.bounds.height * 1.5
            
            switch (recognizer.state) {
                case .Began:
                    interactive = true
                    destinationViewController.dismissViewControllerAnimated(true, completion: nil)
                case .Changed:
                    self.updateInteractiveTransition(delta)
                default:
                    interactive = false
                    if delta > 0.5 {
                        self.finishInteractiveTransition()
                    } else {
                        self.cancelInteractiveTransition()
                    }
            }
        }
    }
    
}

// MARK: - UIViewControllerAnimatedTransitioning
extension MCMHeaderAnimated: UIViewControllerAnimatedTransitioning {
    
    public func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval {
