在UILongPressGestureRecognizer之后在UICollectionViewCell上显示按钮(Display button on UICollectionViewCell aft

编程入门 行业动态 更新时间:2024-10-22 14:01:01
在UILongPressGestureRecognizer之后在UICollectionViewCell上显示按钮(Display button on UICollectionViewCell after UILongPressGestureRecognizer)

我在一个来自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.

更多推荐

本文发布于:2023-07-04 10:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   UICollectionViewCell   UILongPressGestureRecognizer   Display   button

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!