         
         return attr
     }
+    
+    /**
+     Updates the attributes.
+     Here manipulate the zIndex of the cards here, calculate the positions and do the animations.
+     - parameter attributes: The attributes we're updating.
+     */
+    fileprivate func updateCellAttributes(_ attributes: UICollectionViewLayoutAttributes) {
+        let minY = collectionView!.bounds.minY + collectionView!.contentInset.top
+        let maxY = attributes.frame.origin.y
+        
+        let finalY = max(minY, maxY)
+        var origin = attributes.frame.origin
+        let deltaY = (finalY - origin.y) / attributes.frame.height
+        
+        if let itemTransform = firstItemTransform {
+            let scale = 1 - deltaY * itemTransform
+            attributes.transform = CGAffineTransform(scaleX: scale, y: scale)
+            // TODO: add card stack effect (like Shazam)
+        }
+        origin.y = finalY
+        attributes.frame = CGRect(origin: origin, size: attributes.frame.size)
+        attributes.zIndex = attributes.indexPath.row
+    }
 }

    /// Stores the height of a CardCell.
    internal var cellHeight: CGFloat!
    
    override func prepare() {
        super.prepare()
        
        assert(collectionView!.numberOfSections == 1, "Number of sections should always be 1.")
        assert(collectionView!.isPagingEnabled == false, "Paging on the collectionview itself should never be enabled. To enable cell paging, use the isPagingEnabled property of the VerticalCardSwiperFlowLayout instead.")
    }
    
    override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
        let items = NSArray (array: super.layoutAttributesForElements(in: rect)!, copyItems: true)
        
        items.enumerateObjects(using: { (object, index, stop) -> Void in

        return CGPoint(x: proposedContentOffset.x, y: newVerticalOffset)
    }
    
    override internal func finalLayoutAttributesForDisappearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {

        // make sure the zIndex of the next card is higher than the one we're swiping away.
        let nextIndexPath = IndexPath(row: itemIndexPath.row + 1, section: itemIndexPath.section)
