You should add gesture recognizers to the presentation content view.
let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
present(alertController, animated: true, completion: {
let backgroundTapDismissGesture = UITapGestureRecognizer(target: self, action: #selector(didTapDismissGesture(_:)))
let transitionBGView = alertController.presentationController?.containerView?.subviews.first
transitionBGView?.isUserInteractionEnabled = true
transitionBGView?.addGestureRecognizer(backgroundTapDismissGesture)
})
...
@objc func didTapDismissGesture(_ sender: UITapGestureRecognizer) {
alertController.dismiss(animated: true)
}