swift3.0 collectionView添加长按手势识别
2017-10-27 14:14
423 查看
1. 在collectionView绘制cllectionViewCell的代理函数中添加长按识别:
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(cellLongPress(sender:)))
cell.addGestureRecognizer(longPress)
2. 识别长按的位置
func cellLongPress(sender:UILongPressGestureRecognizer) {
//获得点击位置
let touchPoint = sender.location(in: self.collectionView)
//识别是否长按后松开的手势
if (sender.state == UIGestureRecognizerState.ended)
{
let indexPath = self.collectionViewInput.indexPathForItem(at: touchPoint)
if indexPath != nil
{
print("你点击的是第\(indexPath_output!.row + 1)个cell")
}
}
}
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(cellLongPress(sender:)))
cell.addGestureRecognizer(longPress)
2. 识别长按的位置
func cellLongPress(sender:UILongPressGestureRecognizer) {
//获得点击位置
let touchPoint = sender.location(in: self.collectionView)
//识别是否长按后松开的手势
if (sender.state == UIGestureRecognizerState.ended)
{
let indexPath = self.collectionViewInput.indexPathForItem(at: touchPoint)
if indexPath != nil
{
print("你点击的是第\(indexPath_output!.row + 1)个cell")
}
}
}
相关文章推荐
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效
- 为activity添加左右手势识别
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效
- 给webapp添加侧滑的手势识别
- 154在屏幕中绘图时设置透明度(扩展知识:为图片视图添加点击手势识别器,来实现点击事件操作)
- andriod应用程序添加手势识别
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效
- 多个label添加tap手势和识别点击的是哪个label
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效
- 手势识别(三)2种添加手势方法和如何响应手势
- iOS 多个view添加手势, 识别是哪个view的事件
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效