0

UICollectionviewCellアニメーションは、アニメーションは次のようにする必要があります:私は<strong>アニメーション化する</strong> collectionview細胞を望ん

まずセルが表示され、その後、いくつかの遅延の後セルは、いくつかのアニメーション、この意志が表示されますすべての細胞のためにこれのように行ってください。

これを行うには?

答えて

1

データソースを増分的に作成して、設定された時間遅れの後にセルを追加する方法があります。一度、あなたは(この例では)0.05秒ごとにヒットします。このメソッド内で

[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(addToDataSource:) userInfo:nil repeats:YES]; 

次に好き遅らせる何を使ってデータソースに追加するタイマーを設定するために電話をかける

を挿入追加

-(void)addToDataSource:(NSTimer*)timer{ 

    [self.yourMutableDataSourceArray addObject:OBJECT] 

    NSInteger arrayCount = self.yourMutableDataSourceArray.count; 

     [self.collectionView performBatchUpdates:^{ 
      [self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:arrayCount-1 inSection:0]]]; 
     } completion:^(BOOL finished) { 

     }]; 

    //Once you have reached the desired count cells you wish, remember to invalidate the timer 

} 

performBatchUpdateは、collectionViewにアニメーションが再ロードされることを意味します。

は、私は、これは

同じ原理が、あなたが迅速

+0

どこNSThread – Diksha

+0

@Elan呼び出すためにあなたがどこNSTimer」を呼び出すために意味するかロードされたセルをマークする配列ですか?あなたはあなたのviewDidLoadから呼び出すこともできますし、必要に応じてIBActionから呼び出すように設定することもできます。 –

+0

@ Jim Tierney私が望むのは、スクロールして上から下に向かうべきですが、フェードインまたはアウトのように見えます。そのための解決策はありますか? – Diksha

1

でこれを書いている場合は適用されますが、これは、Objective-Cであるが、ここでは、他のソリューションがここにあるwillDisplayCell:forIndexPathデリゲート

を使用しているのに役立ちます願っていますどのように私はそれを行うサンプル。

func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) { 
    if (!loadedIdx.contains(indexPath.row)) { 
     let cellContent = cell 
     let rotationAngleDegrees : Double = -30 
     let rotationAngleRadians = rotationAngleDegrees * (M_PI/180) 
     let offsetPositioning = CGPoint(x: collectionView.bounds.size.width, y: -20) 
     var transform = CATransform3DIdentity 
     transform = CATransform3DRotate(transform, CGFloat(rotationAngleRadians), -50, 0, 1) 
     transform = CATransform3DTranslate(transform, offsetPositioning.x, offsetPositioning.y, -50) 

     cellContent.layer.transform = transform 
     cellContent.layer.opacity = 0.2 

     let delay = 0.06 * Double(indexPath.row) 
     UIView.animateWithDuration(0.8, delay:delay , usingSpringWithDamping: 0.8, initialSpringVelocity: 0.5, options: .CurveEaseIn, animations: {() -> Void in 
      cellContent.layer.transform = CATransform3DIdentity 
      cellContent.layer.opacity = 1 
     }) { (Bool) -> Void in 

     } 

     loadedIdx.append(indexPath.row) 
    } 

} 

loadedIdxは(表示され、次の時間にアニメーション化しない)

+0

私はそれを使用しようとしましたが、コレクションビューをリロードしても動作しません – Diksha

+0

リロード時にloadedIdx配列内の 'removeAllObject'を使いましたか? – EricNguyen

+0

はい私はremoveAllObjectを持っていますが、それでも私が望むようには機能しません – Diksha

関連する問題