title: How to make a UIImageView tappable and cause it to do something? (Swift)
body: <p>(I just started using Swift a few days ago and am relatively new to programming, so please bear with me.) I am trying to make random blocks appear on the screen, and the user must tap them to make them disappear. I have been able to create the blocks, but I have no idea how to actually make them tappable. Can someone please help me? This is my code so far: </p>
  
  <pre><code>func createBlock(){
  
      let imageName = "block.png"
      let image = UIImage(named: imageName)
      let imageView = UIImageView(image: image!)
  
      imageView.frame = CGRect(x: xPosition, y: -50, width: size, height: size)
      self.view.addSubview(imageView)
  
  
  
      UIView.animateWithDuration(duration, delay: delay, options: options, animations: {
  
          imageView.backgroundColor = UIColor.redColor()
  
          imageView.frame = CGRect(x: self.xPosition, y: 590, width: self.size, height: self.size)
  
          }, completion: { animationFinished in
  
  
              imageView.removeFromSuperview()
  
  
      })
  
  
  
  }
  </code></pre>
  
  <p><strong>Edit:</strong> This is the new code I am trying:</p>
  
  <pre><code>func createBlock(){
  
  
      let imageName = "block.png"
      let image = UIImage(named: imageName)
      let imageView = UIImageView(image: image!)
  
      imageView.frame = CGRect(x: xPosition, y: -50, width: size, height: size)
      self.view.addSubview(imageView)
  
      imageView.userInteractionEnabled = true
      let tapRecognizer = UITapGestureRecognizer(target: self, action: Selector("imageTapped"))
      imageView.addGestureRecognizer(tapRecognizer)
  
      func imageTapped(gestureRecognizer: UITapGestureRecognizer) {
          let tappedImageView = gestureRecognizer.view!
          tappedImageView.removeFromSuperview()
          score += 10
      }
  
  
  
      UIView.animateWithDuration(duration, delay: delay, options: options, animations: {
  
          imageView.backgroundColor = UIColor.redColor()
          imageView.frame = CGRect(x: self.xPosition, y: 590, width: self.size, height: self.size)
  
          }, completion: { animationFinished in
  
  
              imageView.removeFromSuperview()
  
  
      })
  
  
  
  }
  </code></pre>