2016-11-01 10 views
0

私はcollectionView.reloadData()でそれを試しましたが、実際にはうまくいきませんでした。私は何をしますか?SwiftでUICollectionViewのアニメーションをアニメーション化するにはどうすればよいですか?

+2

、あなたが使用する必要がある[例えばので あなたは、アイテムの位置を変更する必要がありますinsertItems(at:)](https://developer.apple.com/reference/uikit/uicollectionview/1618097-insertitems)メソッドを使用します。 コードスニペットがないため、一般的な質問ですので、[こちらの記事](http://rshankar.com/uicollectionview-demo-in-swift/) - * Insert Cell *どのように遊ぶことができるかをチェックします。 –

+0

あなたのコメントは答えでなければなりません。 –

答えて

-1

reloadDataはレイアウトを変更したりアニメーション化したりしません。上で見られるように

self.collectionView.performBatchUpdates({ 
       let indexSet = IndexSet(integersIn: 0...0) 
       self.collectionView.reloadSections(indexSet) 
      }, completion: nil) 

:あなたのcollectionviewが唯一つのセクショントライを持っている場合

func shuffleTwoCells(srcIndex index1: Int, destIndex index2: Int) { 
    let firstIndexPath = IndexPath(row: Int(index1), section: 0) 
    let secondIndexPath = IndexPath(row: Int(index2), section: 0) 
    self.collectionView?.moveItem(at: firstIndexPath, to: secondIndexPath) 
} 
+0

しかし、これは2つを交換するためのもので、新しいものを挿入するのではありませんか? –

関連する問題