ios - 在 UILongPressGestureRecognizer 之后在 UICollectionViewCell 上显示按钮

标签 ios swift uigesturerecognizer uicollectionviewcell

我在 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/

相关文章:

iphone - 我怎么知道触发 touchesBegan 的手指也是触发手势的手指?

swift - Pan 手势和 Tap 手势之间的冲突

iphone - 如何更改导航栏下方的边框颜色?

ios - 呈现 View Controller 后更改 iOS 状态栏颜色或导航栏颜色?

ios - swift : show searchbar when scroll up and hide it when scroll down

swift - swift 3 中的类和结构之间的主要区别是什么?

Swift - `范围最小 - 最大范围内的数字

ios - 如何在整个 View 中将 PDFSelection 居中?

iphone - 如何同时执行两个 UI 更新?

ios - 如果 UIGestureRecognizer 触发,如何取消按钮点击?