★ UICollectionViewでCellを自由に動かせるLibrary
UICollectionViews Now Have Easy Reordering
★ セル押下時にIndexPathからセルを取得する
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
// IndexPathからセルを取得する
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! CustomCell
}
★ 現在画面に見えているセルを取得する
let visibleCells = collectionView.visibleCells()
★ 現在表示中のセルでFrame全てが表示されているセルを抽出する
let perfectVisibleCells = collectionView.visibleCells().filter {
return CGRectContainsRect(collectionView.bounds, $0.frame)
}
★ セルが画面に表示される、非表示になるタイミングでセルに処理をする
// 表示されるタイミング
override func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
if let cell = cell as? CustomCell {
// do something
}
}
// 非表示になるタイミング
override func collectionView(collectionView: UICollectionView, didEndDisplayingCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
if let cell = cell as? CustomCell {
// do something
}
}