 import UIKit
 
 class HideDetailAnimator: NSObject, UIViewControllerAnimatedTransitioning {
+    
     private let duration = 0.75
     
     func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {

        
        guard let toCollectionView = toViewController.collectionView else { return }
        guard let fromCollectionView = fromViewController.collectionView else { return }
        
        guard let containerView = transitionContext.containerView() else { return }
        
        // Find origin rect
        guard let originIndexPath = fromCollectionView.indexPathsForVisibleItems().first else { return }
        let originAttributes = fromCollectionView.layoutAttributesForItemAtIndexPath(originIndexPath)
        let originRect = CGRectInset(originAttributes!.frame, 0.0, 0.0)
        let snapshotRect = CGRectMake(originRect.origin.x, originRect.origin.y, originRect.size.width, 64.0)
        
        // Find destination rect
        let destinationAttributes = toCollectionView.layoutAttributesForItemAtIndexPath(originIndexPath)
        var destinationRect = destinationAttributes!.frame
        
        // XXXAJS: Offset destination rect by navigation bar height
        // why does a convertRect not take care of this?
        // doing a convertRect to containerView space makes a weird rectangle
        destinationRect = CGRectMake(destinationRect.origin.x, destinationRect.origin.y + 64.0, destinationRect.size.width, destinationRect.size.height)
        
        let firstRect = CGRectMake(originRect.origin.x, originRect.origin.y, originRect.size.width, destinationRect.size.height)
        let secondRect = destinationRect
        
        let insets = UIEdgeInsets(top: 73.0, left: 0.0, bottom: 1.0, right: 0.0)
        let snapshot = fromCollectionView.resizableSnapshotViewFromRect(snapshotRect, afterScreenUpdates: false, withCapInsets: insets)
        snapshot.frame = containerView.convertRect(originRect, fromView: fromCollectionView)
        
        containerView.addSubview(toViewController.view)
        containerView.addSubview(snapshot)

        }
        return indexPath
    }
    
    private func originRectFromAttributes(attributes: UICollectionViewLayoutAttributes?) -> CGRect {
        return CGRectInset(attributes?.frame ?? CGRectZero, 0.0, 0.0)
    }
    
    private func destinationRectFromAttributes(attributes: UICollectionViewLayoutAttributes?) -> CGRect {
        guard let frame = attributes?.frame else { return CGRectZero }
        let rect = CGRectMake(frame.origin.x, frame.origin.y + 64.0, frame.size.width, frame.size.height)
        return rect
    }
    
    private func lineViewFrameWithBounds(bounds: CGRect) -> CGRect {
        return CGRectMake(CGRectGetMinX(bounds), CGRectGetMaxY(bounds) - 0.5, CGRectGetWidth(bounds), 1.0)
    }
}
