相关疑难解决方法(0)

更改UICollectionView单元格的背景

我有一个以编程方式创建的UICollectionView.我希望集合视图以下列方式运行:

1. User touches cell
2. Cell background color changes
3. User releases touch
4. Cell background color changes
Run Code Online (Sandbox Code Playgroud)

这应该是一个快速的颜色更改,它发生在与执行tap操作相关的选择器之前,其中包含集合视图的viewcontroller从堆栈中弹出.

我一直在看这个问题:UICollectionView单元格改变背景,同时点击

其中有以下用于此目的的方法摘要:

// Methods for notification of selection/deselection and highlight/unhighlight events.
// The sequence of calls leading to selection from a user touch is:
//
// (when the touch begins)
// 1. -collectionView:shouldHighlightItemAtIndexPath:
// 2. -collectionView:didHighlightItemAtIndexPath:
//
// (when the touch lifts)
// 3. -collectionView:shouldSelectItemAtIndexPath: or -    collectionView:shouldDeselectItemAtIndexPath:
// 4. -collectionView:didSelectItemAtIndexPath: or -collectionView:didDeselectItemAtIndexPath:
// 5. -collectionView:didUnhighlightItemAtIndexPath:
Run Code Online (Sandbox Code Playgroud)

我假设我只需要从"触摸开始时"和"触摸结束时"实现上述方法之一.但无论我做什么,似乎背景颜色会发生变化,然后仍然会发生变化.这是我尝试过的一些不起作用的例子:

- (void)collectionView:(UICollectionView …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview uicollectionviewcell uicollectionviewdelegate

32
推荐指数
3
解决办法
4万
查看次数