0

I have several imageViews and I want to add one tapRecognizer for all imageViews.

So I know how to add tapRecognizer.

let tapRecognizer = UITapGestureRecognizer(target: self, action: "imageTapped:")
imageViewOne.addGestureRecognizer(tapRecognizer)

It works, but I also want to add this for rest like

imageViewOne.addGestureRecognizer(tapRecognizer)
imageViewTwo.addGestureRecognizer(tapRecognizer)
imageViewThree.addGestureRecognizer(tapRecognizer)
imageViewFour.addGestureRecognizer(tapRecognizer) 
...etc

But here the imageTapped method will work only for the last one.

Question is: is it possible to do it not creating new tapRecognizers for each imageView?

aaisataev
  • 1,643
  • 3
  • 22
  • 38

1 Answers1

0

No, Its not possible with 1 TapGesture. You need to create separate tap gesture for each image view, even you can set same target method for all tap gesture.

If you are going to create several images with tap gesture then you need to make a separete method and create each image view with tap gesture in for loop.

Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66