我在一个来自CollectionView的Cell上有一个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。
提前致谢
I have a UILongPressGestureRecognizer on a Cell from a CollectionView and I want to display a button from that (and all the others) cells after a long touch happens. Here's my code:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell: CellController = collection.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CellController cell.exitButton.hidden = true return cell }I want to set to false the cell.exitButton.hidden after the touch happen.
Thanks in advance
最满意答案
在collectionView的类范围中有一个bool变量。 检测到长按时,请修改bool变量。 在这个例子中,我将它声明为var exitButtonHidden = true 。
更改cellForItemAtIndexPath的实现, cellForItemAtIndexPath将cell.exitButton.hidden = true修改为cell.exitButton.hidden = exitButtonHidden 。
现在,您需要做的是每当检测到长reloadData在collectionView上调用reloadData ,以便collectionView有机会再次刷新所有单元格。
Have a bool variable in the collectionView's class scope. When you detect the long press, modify the bool variable. In this example, I'll declare it as var exitButtonHidden = true.
Change your implementation of cellForItemAtIndexPath, such that it modifies cell.exitButton.hidden = true to cell.exitButton.hidden = exitButtonHidden.
Now, you need to do is call reloadData on the collectionView whenever you detect the long press so that the collectionView gets a chance to refresh all the cells again.
更多推荐
发布评论