我在 CollectionView 的单元格上有一个 UILongPressGestureRecognizer,我想在长触摸发生后显示该单元格(以及所有其他单元格)的按钮。这是我的代码:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: CellController = collection.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CellController
cell.exitButton.hidden = true
return cell
}
我想在触摸发生后将 cell.exitButton.hidden
设置为 false。
提前致谢
最佳答案
在collectionView的类范围内有一个bool变量。当检测到长按时,修改 bool 变量。在此示例中,我将其声明为 var exitButtonHidden = true
。
更改 cellForItemAtIndexPath
的实现,以便将 cell.exitButton.hidden = true
修改为 cell.exitButton.hidden = exitButtonHidden
。
现在,您需要做的是每当检测到长按时就调用 CollectionView 上的 reloadData
,以便 CollectionView 有机会再次刷新所有单元格。
关于ios - 在 UILongPressGestureRecognizer 之后在 UICollectionViewCell 上显示按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30824107/