title: Dismiss UIAlertViewController by tapping outside
body: <p>I want to dismiss my UIAlertViewController by tapping outside of the UIAlertViewController, on tapping on black screen space. I've tried this:</p>
  
  <pre><code>self.presentViewController(alertViewController, animated: true, completion:{
          alertViewController.view.superview?.userInteractionEnabled = true
          alertViewController.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.alertClose(_:))))
      })
  </code></pre>
  
  <p>but it just closes if I tapped on UIAlertViewController. But I want outside, where half-blacked screen tapped.</p>
  
  <p>Is it possible?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>@IBAction func shareButtonTapped(sender: UIButton) {
      let alertViewController = UIAlertController(title: "Share on social networks", message: "Where do you want to share?", preferredStyle: .ActionSheet)
  
      let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissAlertView:")
      self.view.addGestureRecognizer(tapGestureRecognizer)
  
      let facebookAction = UIAlertAction(title: "Facebook", style: .Default) { (alert: UIAlertAction) -&gt; Void in
  
      }
  
      let twitterAction = UIAlertAction(title: "Twitter", style: .Default) { (alert: UIAlertAction) -&gt; Void in
  
      }
  
      let cancelAction = UIAlertAction(title: "Cancel", style: .Destructive) { (alert: UIAlertAction) -&gt; Void in
  
      }
  
      alertViewController.addAction(facebookAction)
      alertViewController.addAction(twitterAction)
      alertViewController.addAction(cancelAction)
  
      self.presentViewController(alertViewController, animated: true, completion:{
          alertViewController.view.superview?.userInteractionEnabled = true
          alertViewController.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.alertClose(_:))))
      })
  }
  </code></pre>
  
  <p>AlertClose function:</p>
  
  <pre><code>func alertClose(gesture: UITapGestureRecognizer) {
      self.dismissViewControllerAnimated(true, completion: nil)
  }
  </code></pre>