Upvote:5

Aprove answer
static func addNewTapGuestureRecognizer(for imageView: UIImageView, target: Any, selectorName: Selector) {
    let tap = UITapGestureRecognizer(target: target, action: selectorName)
    imageView.addGestureRecognizer(tap)
    imageView.isUserInteractionEnabled = true
}

Upvote:2

static func addNewTapGuestureRecognizer(for imageView: UIImageView, selectorName: Selector , myTarget:UICollectionViewCell) {

     let tap = UITapGestureRecognizer(target: myTarget, action: selectorName)


 }

Credit Goes to: stackoverflow.com

Related question with same questions but different answers