UICollectionView放大select的单元格

我想在选中时调整我的collections夹视图中的特定单元格。 我发现如何从以前的post,但遇到了一个问题。 我发现debugging时select滞后一个,但我不知道为什么。

例如,如果我通过点击select一个单元格,则什么都不会发生。 如果我select另一个单元格后,那么我select的第一个单元格被放大。 如果我select第三个单元格,则第二个单元格会放大。 等等。

这就是我实现的方式,只有一次细胞像我想要的那样同时放大:

var selectedIndexPath: NSIndexPath! func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { if selectedIndexPath != nil { //We know that we have to enlarge at least one cell if indexPath == selectedIndexPath { return CGSize(width: self.gallery.frame.size.width, height: self.gallery.frame.size.width) } else { return CGSize(width: self.gallery.frame.size.width/3.0, height: self.gallery.frame.size.width/3.0) } } else { return CGSize(width: self.gallery.frame.size.width/3.0, height: self.gallery.frame.size.width/3.0) } } func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) { if selectedIndexPath != nil && selectedIndexPath == indexPath { selectedIndexPath = nil //Trigger large cell set back to normal } else { selectedIndexPath = indexPath //User selected cell at this index } collectionView.reloadData() } 

我发现,debugging时,select滞后于didDeselectItemAtIndexPath上述方式,但我不知道为什么。

问题是你正在使用func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath)

注意这个短语:做了取消select ItemAtIndexPath。

没有select ItemAtIndexPath是一种方法。