Skip to content

Commit

Permalink
Fix for IQKeyboardManager (#53)
Browse files Browse the repository at this point in the history
Fix to make `CardTextField` selectable via IQKeyboardManager's next and previous buttons.
Resolves #52
  • Loading branch information
DannyVancura committed Apr 28, 2016
1 parent c3f85e2 commit 851c1ce
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions Pod/Classes/UI/CardTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,28 @@ public class CardTextField: UITextField, NumberInputTextFieldDelegate {
}

public override func becomeFirstResponder() -> Bool {
// Return false, since this text view is only for background style purposes
return false
// Return false if any of this text field's subviews is already first responder.
// Otherwise let `numberInputTextField` become the first responder.
if [numberInputTextField,monthTextField,yearTextField,cvcTextField]
.flatMap({return $0.isFirstResponder()})
.reduce(true, combine: {$0 && $1}) {
return false
}
return numberInputTextField.becomeFirstResponder()
}

public override func isFirstResponder() -> Bool {
// Return true if any of `self`'s subviews is the current first responder.
return [numberInputTextField,monthTextField,yearTextField,cvcTextField]
.filter({$0.isFirstResponder()})
.isEmpty == false
}

public override func resignFirstResponder() -> Bool {
// If any of `self`'s subviews is first responder, resign first responder status.
return [numberInputTextField,monthTextField,yearTextField,cvcTextField]
.filter({$0.isFirstResponder()})
.first?
.resignFirstResponder() ?? true
}
}

0 comments on commit 851c1ce

Please sign in to comment.