collectionViewCell即将显示的时候动画

// Cell即将显示的时候调用
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (self.flowLayout.columnNumber == 2) {
        
        // 将所有已经显示过的cell放在showedIndexPaths数组中,只有第一次显示的时候才需要做动画
        if ([self.showedIndexPaths containsObject:indexPath]) {
            return;
        } else {
            [self.showedIndexPaths addObject:indexPath];
            // 给cell做缩放动画
            [self cellAnimateScale:cell];
        }
    }
}

// 缩放动画
- (void)cellAnimateScale:(UICollectionViewCell *)cell {
    CGFloat duration = 0.5;
    cell.transform = CGAffineTransformMakeScale(0.3, 0.3);
    [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
        cell.transform = CGAffineTransformMakeScale(1.0, 1.0);
    } completion:^(BOOL finished) {
        
    }];
}

// 移动动画-- 暂时不用-- 备用
- (void)cellAnimateMove:(UICollectionViewCell *)cell indexPath:(NSIndexPath *)indexPath {
    NSLog(@"%@",NSStringFromCGRect(cell.frame));
    
    CGRect toFrame = cell.frame;
    // Y ScrollView滑动到底部的时的Y
    cell.frame = CGRectMake(cell.frame.origin.x, self.collectionView.contentSize.height + self.collectionView.contentOffset.y + self.collectionView.contentInset.top, cell.bounds.size.width, cell.bounds.size.height);
    cell.layer.cornerRadius = cell.bounds.size.width * 0.5;
    
    CGFloat duration = (indexPath.item) * 0.2 + 0.2;
    [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
        cell.frame = toFrame;
        
    } completion:^(BOOL finished) {
        
    }];
}

你可能感兴趣的:(collectionViewCell即将显示的时候动画)