swift - UIcollectionview 滚动时调用 func(didSelectItemAt)
问题描述
目前我正在使用UICollectionView
其中的几个单元格。 UICollectionView
水平滚动以在单元格之间移动。
我的问题是:有没有办法通过在滚动时UICollectionView
单击单元格来调用 func(didSelectItemAt) ?
这是gif。
在将单元格向左拖动以进行滚动后,我连续单击单元格以调用 func(didSelectItemAt) 但仅在滚动完成时才会调用。是否可以在滚动时单击单元格后立即调用 func(didSelectItemAt) ?
这是我的 collectionView 委托和数据源代码。
extension CardViewController : UICollectionViewDelegate,UICollectionViewDataSource {
public func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return cardCount
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = cardCollectionView.dequeueReusableCell(withReuseIdentifier: "card", for: indexPath) as! CardCell
cell.isFront = cellsSelectedStatus[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = cardCollectionView.cellForItem(at: indexPath) as! CardCell
UIView.transition(with: cell, duration: 0.3, options: [.transitionFlipFromLeft,.allowUserInteraction], animations: nil, completion: nil)
cellsSelectedStatus[indexPath.row] = !(cellsSelectedStatus[indexPath.row])
cell.isFront = cellsSelectedStatus[indexPath.row]
print("did select")
}
Collectionview 的 dataSource&delegate 在viewDidLoad
.
我知道有一个允许在动画时单击视图allowUserInteraction
。UIViewAnimationOptions
func(didSelectItemAt) 是否有更简洁的代码?
没有网络和 UIGestureRecognizers 附加到单元格或集合视图。到目前为止,我已将 collectionView 的 , , 设置
isUserInteractionEnabled
为
isMultipleTouchEnabled
true
allowsMultipleSelection
,但它的行为仍然相同。我正在使用 Swift3、Xcode9。
提前致谢。
解决方案
推荐阅读
- matlab - 如何在 MATLAB 中为 ode15s 中的选项结构编写自定义“输出函数”以存储解向量的历史?
- javascript - 从字符串中删除某些重复出现的字符
- flutter - 使用 Dart 进行实时语音转录
- python - 如何使用 Telethon 获取传入电报消息的聊天或群组名称?
- flutter - 颤振 - 从底部到顶部的按钮动画
- java - Firestore 讲座操作计数
- python - 将长列表与数据框中的字符串进行比较,并在匹配的基础上填充 Python 中的数据框
- java - Recyclerview 没有第一次加载( Firebase )
- reactjs - React JS,显示来自嵌套 json 的数据
- javascript - 是否可以使用javascript获取屏幕颜色?