IQKeyboardReturnManager

CI Status Version License Platform

Screenshot

示例

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install

要求

安装

IQKeyboardReturnManager 可通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中

pod 'IQKeyboardReturnManager'

用法

要自动处理键盘返回键,请执行以下操作:

import IQKeyboardReturnManager

class ViewController: UIViewController {

    let returnManager: IQKeyboardReturnManager = .init()

    override func viewDidLoad() {
        super.viewDidLoad()

        // This will add all textInputView of the controller and start observing for textFieldShouldReturn events
        returnManager.addResponderSubviews(of: self.view, recursive: true)

        // If you would like to dismiss the UITextView on tapping on return then add this
        returnManager.dismissTextViewOnReturn = true

        // If you would like to change last textInputView return key type to done or something else, then add this
        returnManager.lastTextInputViewReturnKeyType = .done

        // If you would like to customize the navigation between textField by your own order then add them manually
        returnManager.add(textInputView: textField1)
        returnManager.add(textInputView: textField2)
        returnManager.add(textInputView: textField3)
        returnManager.add(textInputView: textField4)
    }
}

// IQKeyboardReturnManager will forward all delegate callbacks to you, so you can customize the decisions 
extension ViewController: UITextFieldDelegate {
    @objc public func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {...}
}

作者

Iftekhar Qurashi hack.iftekhar@gmail.com

许可证

IQKeyboardReturnManager 在 MIT 许可证下可用。有关更多信息,请参见 LICENSE 文件。