これを試して:
import UIKit
private let reuseIdentifierBig = "bigger"
private let reuseIdentifierSmall = "small"
class CollectionViewController: UICollectionViewController {
let array = [0,1,2,3,4]
var selectedIndex:NSIndexPath?
var preSelectedIndex:NSIndexPath?
override func viewDidLoad() {
super.viewDidLoad()
}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return array.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if selectedIndex != indexPath {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifierSmall, forIndexPath: indexPath)
return cell
} else {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifierBig, forIndexPath: indexPath)
return cell
}
}
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
preSelectedIndex = selectedIndex
selectedIndex = indexPath
collectionView.reloadItemsAtIndexPaths([indexPath])
if preSelectedIndex != nil {
collectionView.reloadItemsAtIndexPaths([preSelectedIndex!])
}
}
}