Ios 轻触手势识别器不';t在imageview上工作';因为准备工作,他在牢房上面吗?
因为我有一个链接到单元格的序列,可以将图像从单元格传递到另一个视图,所以在单元格顶部的imageview上点击不起作用Ios 轻触手势识别器不';t在imageview上工作';因为准备工作,他在牢房上面吗?,ios,swift,cell,gesture,tap,Ios,Swift,Cell,Gesture,Tap,因为我有一个链接到单元格的序列,可以将图像从单元格传递到另一个视图,所以在单元格顶部的imageview上点击不起作用 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "photoview" { let vc = segue.destination as! PhotoViewController let cell = sender as!
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "photoview" {
let vc = segue.destination as! PhotoViewController
let cell = sender as! UICollectionViewCell
if let indexPath = self.collectionView?.indexPath(for: cell) {
vc.mainURL = self.images[indexPath.row].rawURL
}
}
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as UICollectionViewCell
cellImageView = cell.viewWithTag(1) as! UIImageView
photographerImageView = cell.viewWithTag(4) as! UIImageView
photographerLabel = cell.viewWithTag(5) as! UILabel
photographerLabel.text = images[indexPath.row].photographerName
photographerImageView.image = images[indexPath.row]
/* var tapImage = UITapGestureRecognizer()
photographerImageView = cell.viewWithTag(4) as! UIImageView
tapImage = UITapGestureRecognizer(target: self, action: #selector(CollectionViewController.openPhotographerPortfolio))
tapImage.numberOfTapsRequired = 1
photographerImageView.isUserInteractionEnabled = true
photographerImageView.addGestureRecognizer(tapImage) */
addDropshadow(toView: photographerImageView)
addDropshadow(toView: photographerLabel)
collectionView.bringSubview(toFront: photographerImageView)
photographerImageView.layer.cornerRadius = photographerImageView.frame.width / 2
photographerImageView.layer.masksToBounds = false
photographerImageView.clipsToBounds = true
photographerImageView.isUserInteractionEnabled = true
photographerImageView.addGestureRecognizer(tapImage)
return cell
}
在collectionview控制器类中,
tapImage
?的声明在哪里。与这个@NiravD相比,我不想向标签中添加一个点击手势,只向图像视图中添加,但是它不起作用。我要说的是,您需要为表的每个单元格创建tap手势实例。而不仅仅是一个。因此,在cellForItemAt
中创建一个TapSirture实例,并将其添加到imageView中。