CocoaPods trunk is moving to be read-only. Read more on the blog, there are 14 months to go.
| TestsTested | ✗ |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Dec 2018 |
| SPMSupports SPM | ✗ |
Maintained by Vlad Alexa, Ben Baggley, James Shaw, Anh Tran.
Easy navigation between UITextFields and UITextViews.
UITextFields and UITextViews correctly maintaining UIScrollView insets and offsetsinputAccessoryView with default UIToolbar implementation.Keyboard Responder is dependent on other libraries available from The Distance:
Ensure you add these to your project alongside KeyboardResponder.
KeyboardResponder has a very simple set up.
KeyboardResponder objectscrollContainer to ensure contentOffset and contentInsets are adjusted to keep the view on screen.inputAccessoryView on the KeyboardResponder - when components are added to the keyboard responder there inputAccessoryView will be set to this.KeyboardResponderInputTypes from UITextFields and UITextViews, assign in to the components property.textView's height to just fit its contents.That's it! When any of your fields become first responder they will appear with your inputAccessoryView and you can navigate between them, maintaining consistent scroll offset.
class ViewController: UIViewController {
@IBOutlet weak var titleField:UITextField?
@IBOutlet weak var nameField:UITextField?
@IBOutlet weak var emailField:UITextField?
@IBOutlet weak var textView:UITextView?
@IBOutlet weak var scrollView:UIScrollView?
var responder:KeyboardResponder!
override func viewDidLoad() {
super.viewDidLoad()
// 1.
responder = KeyboardResponder()
// 2.
responder.scrollContainer = scrollView
// 3.
responder.inputAccessoryView = KeyboardResponderToolbar(navigationDelegate: responder)
// 4.
if let tf = titleField, tv = textView, ef = emailField, nf = nameField {
responder.components = [.TextField(tf), .TextField(nf), .TextView(tv), .TextField(ef)]
}
// 5.
textView?.textContainer.heightTracksTextView
}
}
To create user input forms even easier, we have developed TheDistanceForms - an iOS framework for creating flexible forms as generic collections of user input elements - which is coming soon.
KeyboardResponderToolbar is a default implementation of the KeyboardResponderInputAccessoryView. You can create any arbitrary UIView that can be used instead providing it conforms to that protocol.
To respond to any UITextField or UITextView delegate methods to add further functionality, you should assign your delegate to the textFieldDelegate or textViewDelegate properties on KeyboardResponder.
To customise functionality, such as preventing navigation in certain situations, you should subclass KeyboardResponder, remembering to call through to super.