Skip to content

Commit

Permalink
Merge pull request #38 from klauslanza/add-background-dismiss
Browse files Browse the repository at this point in the history
Add background dismiss
  • Loading branch information
pmusolino committed Mar 21, 2017
2 parents 59fb7f8 + 68fbe92 commit 493939e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Library/PMAlertController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import UIKit
open var textFields: [UITextField] = []

open var gravityDismissAnimation = true
open var dismissWithBackgroudTouch = false // enable touch background to dismiss. Off by default.

//MARK: - Lifecycle

Expand Down Expand Up @@ -68,6 +69,9 @@ import UIKit
//if alert width = 270, else width = screen width - 36
style == .alert ? (alertViewWidthConstraint.constant = 270) : (alertViewWidthConstraint.constant = UIScreen.main.bounds.width - 36)

let tapRecognizer: UITapGestureRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(dismissAlertControllerFromBackgroundTap))
alertMaskBackground.addGestureRecognizer(tapRecognizer)
alertMaskBackground.isUserInteractionEnabled = true

setShadowAlertView()
}
Expand All @@ -94,6 +98,15 @@ import UIKit
self.dismiss(animated: true, completion: nil)
}

@objc fileprivate func dismissAlertControllerFromBackgroundTap() {
if !dismissWithBackgroudTouch {
return
}

self.animateDismissWithGravity(.cancel)
self.dismiss(animated: true, completion: nil)
}

//MARK: - Text Fields
@objc open func addTextField(_ configuration: (_ textField: UITextField?) -> Void){
let textField = UITextField()
Expand Down

0 comments on commit 493939e

Please sign in to comment.