import UIKit /** Custom layout that allows for smooth resize animation. */ class PPCollectionViewLayout: UICollectionViewLayout { public var viewWidth: CGFloat = 0.0 public var spacing: CGFloat = 6.0 public weak var itemsInfoProvider: (UICollectionViewDataSource & UICollectionViewDelegateFlowLayout)! private var attributes: [UICollectionViewLayoutAttributes] = [] private var contentSize = CGSize.zero override func prepare() { super.prepare() attributes = [] var origin = CGPoint() let itemsCount = itemsInfoProvider.collectionView(collectionView!, numberOfItemsInSection: 0) for index in 0.. [UICollectionViewLayoutAttributes]? { var layoutAttributes: [UICollectionViewLayoutAttributes] = [] for itemAttributes in attributes { if (rect.intersects(itemAttributes.frame) == true) { layoutAttributes.append(itemAttributes) } } return layoutAttributes } override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { if (attributes.count > indexPath.row) { return attributes[indexPath.row] } else { return nil } } override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { return false } }