use*_*256 3 iphone xcode ipad ios swift
我非常喜欢快速,所以我有一个问题,以解决我的应用程序中的麻烦.
在UIView我刚刚添加了一个集合视图作为子视图,然后在每个单元格中我在"包装视图"中添加了一个不同的IMAGE,所以我的问题是......
如何为每个单元格添加发件人接收标记值的手势?例如,当我点击单元格时,它将打印indexPath
我有这个代码:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
var cell:UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("collectionCell", forIndexPath: indexPath) as! UICollectionViewCell;
cell.backgroundColor = UIColor.blueColor().colorWithAlphaComponent(0);
//Agregamos imagen a la celda
var imageView = UIImageView(frame: CGRectMake(0, 0, cell.frame.width - 0, cell.frame.height - 0))
var image = UIImage(named: "car_aguas_gerber_7.png")
imageView.image = image
cell.backgroundView = UIView()
cell.backgroundView!.addSubview(imageView)
// Sección donde creamos el TAP para cada imageView
// Creamos el tap gesture recognizer
let tapGesture = UITapGestureRecognizer(target: self, action: "tapGesture:")
// Se lo adjudicamos al image view previo
cell.addGestureRecognizer(tapGesture)
// Nos aseguramos que tenga interacción hacia el usuario
cell.userInteractionEnabled = true
cell.tag = indexPath.row;
println(cell.tag);
//Una vez creada la celda la regresamos completa.
return cell;
}
Run Code Online (Sandbox Code Playgroud)
非常感谢你的知识和帮助:)
Hen*_*ros 12
将手势识别器添加到单元格时,您就可以使用它.当手势发生时,传递的参数将是单元格.因此,在声明tapGesture方法时,您只需访问sender的tag属性.
func tapGesture(sender: UITapGestureRecognizer) {
var tag = sender.view!.tag
//do what you want
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4526 次 |
| 最近记录: |