Skip to content

Commit

Permalink
Prevent calling keyboardWillShow more than twice to fix #37
Browse files Browse the repository at this point in the history
  • Loading branch information
candostdagdeviren committed Jun 22, 2018
1 parent 2dd7b90 commit a7452dc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CDAlertView/Classes/CDAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ open class CDAlertView: UIView {
private var messageLabel: UILabel = UILabel(frame: .zero)
private var textField: UITextField = UITextField(frame: .zero)
private var type: CDAlertViewType!
private var isKeyboardVisible: Bool = false
weak private var hideTimer: Timer!
public var headerHeight: CGFloat = CDAlertViewConstants().headerHeight

Expand Down Expand Up @@ -402,6 +403,10 @@ open class CDAlertView: UIView {
}

@objc func keyboardWillShow(_ notification: Notification) {
if isKeyboardVisible {
return
}
isKeyboardVisible = true
guard let userInfo = notification.userInfo else {
return
}
Expand All @@ -414,12 +419,14 @@ open class CDAlertView: UIView {
if coverViewWindowCoordinates.y <= (keyboardSize.minY - keyboardSize.height) {
return
}

popupCenterYPositionBeforeKeyboard = popupView.center.y
let difference = coverViewWindowCoordinates.y - (keyboardSize.minY - keyboardSize.height)
popupView.center.y -= difference
}

@objc func keyboardWillHide(_ notification: Notification) {
self.isKeyboardVisible = false
guard let initialY = self.popupCenterYPositionBeforeKeyboard else {
return
}
Expand Down

0 comments on commit a7452dc

Please sign in to comment.