diff --git a/AsyncDisplayKit/ASPagerFlowLayout.m b/AsyncDisplayKit/ASPagerFlowLayout.m index 92afbcfe0d..76e69208e8 100644 --- a/AsyncDisplayKit/ASPagerFlowLayout.m +++ b/AsyncDisplayKit/ASPagerFlowLayout.m @@ -34,6 +34,9 @@ - (CGPoint)_targetContentOffsetForItemAtIndexPath:(NSIndexPath *)indexPath proposedContentOffset:(CGPoint)proposedContentOffset { + if ([self _dataSourceIsEmpty]) { + return proposedContentOffset; + } UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:indexPath]; CGFloat xOffset = (self.collectionView.bounds.size.width - attributes.frame.size.width) / 2; return CGPointMake(attributes.frame.origin.x - xOffset, proposedContentOffset.y); @@ -41,10 +44,6 @@ - (NSIndexPath *)_indexPathForVisiblyCenteredItem { - if ([self _dataSourceIsEmpty]) { - return nil; - } - CGRect visibleRect = [self _visibleRect]; CGFloat visibleXCenter = CGRectGetMidX(visibleRect); NSArray *layoutAttributes = [self layoutAttributesForElementsInRect:visibleRect];