             delay += 0.1 * 2
         }
 
-
         let transformAnimation = CABasicAnimation(keyPath: "position.y")
         transformAnimation.duration = 0.3
         transformAnimation.fromValue = offset + CGFloat(itemIndexPath.section) * (cellSize.height + cellSpace)

            delay += 0.1 * 2
        }


        let transformAnimation = CABasicAnimation(keyPath: "position.y")
        transformAnimation.duration = 0.3
        transformAnimation.fromValue = offset + CGFloat(itemIndexPath.section) * (cellSize.height + cellSpace)
        transformAnimation.toValue = 200 + CGFloat(itemIndexPath.section) * (cellSize.height + cellSpace)
        transformAnimation.timingFunction = CAMediaTimingFunction(controlPoints: 0.45, 1.2, 0.75, 1.0)
        transformAnimation.removedOnCompletion = false
        transformAnimation.fillMode = kCAFillModeForwards
        transformAnimation.beginTime = CACurrentMediaTime() + delay

        let attributes = MSTumblrMenuLayoutAttributes(forCellWithIndexPath: itemIndexPath)
        attributes.animation = transformAnimation
        attributes.size = self.cellSize
        attributes.center = CGPointMake(CGFloat(itemIndexPath.row) * (cellSize.width + cellSpace) + cellSize.width / 2,  offset + CGFloat(itemIndexPath.section) * (cellSize.height + cellSpace) + cellSize.height / 2)
        return attributes
    }



class MSTumblrMenuFlowLayout: UICollectionViewLayout {

    var cellSize = CGSizeMake(100, 100)
    let cellSpace: CGFloat = 20.0
    var indexPathsToAnimate : Array<NSIndexPath>!
    var cachedAttributes = [NSIndexPath: MSTumblrMenuLayoutAttributes]()

    override func prepareLayout() {
        super.prepareLayout()
        cachedAttributes.removeAll(keepCapacity: false)
        let height = collectionViewContentSize().height
        let width = collectionViewContentSize().width
        let numberOfSections = self.collectionView!.numberOfSections()
        let minY = (height - CGFloat(numberOfSections) * (cellSize.height + cellSpace) + cellSpace) / 2
        for section in 0..<numberOfSections {
            let numberOfItems = self.collectionView!.numberOfItemsInSection(section)
            let minX = (width - CGFloat(numberOfItems) * (cellSize.width + cellSpace) + cellSpace) / 2
            for item in 0..<numberOfItems {
                let indexPath = NSIndexPath(forItem: item, inSection: section)
                let attributes = MSTumblrMenuLayoutAttributes(forCellWithIndexPath: indexPath)
                attributes.size = self.cellSize
                attributes.center = CGPointMake(minX + CGFloat(indexPath.row) * (cellSize.width + cellSpace) + cellSize.width / 2, minY + CGFloat(indexPath.section) * (cellSize.height + cellSpace) + cellSize.height / 2)
                cachedAttributes[indexPath] = attributes
            }
        }
