jch*_*nxu 19 uiresponder uigesturerecognizer ios uicollectionview swift
添加单击手势UICollectionView,不要妨碍单元格选择.
我想在collectionView的无单元格部分进行一些其他的点击.
使用XCode8,Swift 3.
override func viewDidLoad() {
...
collectionView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tap)))
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print(indexPath)
}
func tap(sender: UITapGestureRecognizer){
print("tapped")
}
Run Code Online (Sandbox Code Playgroud)
是的,它现在阻碍了它.当您点击单元格时,它会记录"轻拍".
找不到更多的痕迹.有关如何实施细胞选择或实现此任务的任何想法?
Jos*_*ann 27
每当您想要添加手势识别器,但不想从目标视图中窃取触摸时,您应该将实例设置UIGestureRecognizer.cancelsTouchesInView 为gestureRecognizerfalse.
Fra*_*kie 11
而不是试图强迫didSelectItem你可以这样获取indexPath和/或单元格:
func tap(sender: UITapGestureRecognizer){
if let indexPath = self.collectionView?.indexPathForItem(at: sender.location(in: self.collectionView)) {
let cell = self.collectionView?.cellForItem(at: indexPath)
print("you can do something with the cell or index path here")
} else {
print("collection view was tapped")
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17810 次 |
| 最近记录: |