如何检测哪个图像已经被快速切入

我在ViewController上创build了6个UIImageView,后来我将其添加到了所有的TapGestureRecognizers中。

我想这样做,根据被点击的图像,另一个ViewController将打开并显示某些信息。

要做到这一点,我需要知道哪个图像被点击。 我将如何在Swift中执行此操作?

UIGestureRecognizer有属性“视图”,这个属性是你添加的视图。 对于这个例子imageView。

func tap(gesture: UIGestureRecognizer) { println(gesture.view!.tag) // You can check for their tag and do different things based on tag } let img = UIImageView() img.userInteraction = true img.tag = 0 img.addGestureRecognizer(UITapGestureRecognizer(self, action: "tap:"))