From e5355a29dbcbb3c40d186c3c8a206e7d8b5cbce2 Mon Sep 17 00:00:00 2001 From: WenchaoD Date: Wed, 5 Apr 2017 16:59:26 +0800 Subject: [PATCH] Remove UICollectionViewLayoutAttributes cache. --- Sources/FSPageViewLayout.swift | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Sources/FSPageViewLayout.swift b/Sources/FSPageViewLayout.swift index cd81d46..f434fb7 100644 --- a/Sources/FSPageViewLayout.swift +++ b/Sources/FSPageViewLayout.swift @@ -25,7 +25,7 @@ class FSPagerViewLayout: UICollectionViewLayout { fileprivate var pagerView: FSPagerView? { return self.collectionView?.superview?.superview as? FSPagerView } - fileprivate var layoutAttributes: [IndexPath:FSPagerViewLayoutAttributes] = [:] + fileprivate var layoutAttributesQueue: [FSPagerViewLayoutAttributes] = [] fileprivate var isInfinite: Bool = true fileprivate var collectionViewSize: CGSize = .zero @@ -60,7 +60,6 @@ class FSPagerViewLayout: UICollectionViewLayout { self.needsReprepare = false self.collectionViewSize = collectionView.frame.size - self.layoutAttributes.removeAll() // Calculate basic parameters/variables self.numberOfSections = pagerView.numberOfSections(in: collectionView) @@ -147,16 +146,11 @@ class FSPagerViewLayout: UICollectionViewLayout { } override open func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { - var attributes = self.layoutAttributes[indexPath] - if attributes == nil { - attributes = FSPagerViewLayoutAttributes(forCellWith: indexPath) - self.layoutAttributes[indexPath] = attributes - } + let attributes = FSPagerViewLayoutAttributes(forCellWith: indexPath) let frame = self.frame(for: indexPath) let center = CGPoint(x: frame.midX, y: frame.midY) - attributes!.center = center - attributes!.size = self.actualItemSize - self.layoutAttributes[indexPath] = attributes + attributes.center = center + attributes.size = self.actualItemSize return attributes }