それほど難しいことではありません。実際には、すべてセルのロード方法に依存します。たとえば、私が作成したばかりの簡単なハック:
AnimatedCell.m
UICollectionViewCell サブクラス
- (void)setImage:(UIImage*)image animatedWithDelay:(NSTimeInterval)delay
{
self.imageView.image = image;
// Apply the change immediately
if (delay < 0.01)
{
return;
}
self.imageView.alpha = 0.0;
[UIView animateWithDuration:0.5 delay:delay options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveEaseInOut animations:^{
self.imageView.alpha = 1.0;
} completion:nil];
}
これは UIView の便利なアニメーション メソッドを使用した単純なフェードインです。とにかく、コンテンツを設定し、適切な遅延を計算する必要があります。
ViewController.m
UICollectionViewDataSource および UICollectionViewDelegate に準拠
@interface ViewController () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic,assign) CGFloat delay;
@end
@implementation ViewController
CGFloat const kDelayMinimum = 0.02;
CGFloat const kDelayIncrement = 0.01;
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
AnimatedCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection.cell" forIndexPath:indexPath];
[cell setImage:[UIImage imageNamed:@"photo.png"] animatedWithDelay:self.delay];
self.delay += kDelayIncrement;
return cell;
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.delay = kDelayMinimum;
}
// <Rest of the code>
@end
これは本当に単純なトリックです。表示されている各セルの遅延を増やすだけです。ユーザーがスクロールすると、遅延が最小にリセットされます。そうしないと、遅延が大きくなり、制御不能になります。
それをデータ ソースに適切にプラグインする方法、画像が読み込まれていない状況に対処する方法などを理解する必要がありますが、これを作業の基礎と考えてください。