轻量级库,可轻松观察键盘事件。
要运行示例项目,请克隆存储库,然后首先从示例目录运行 pod install
。
IQKeyboardNotification 可通过 CocoaPods 获得。 要安装它,只需将以下行添加到您的 Podfile 中
pod 'IQKeyboardNotification'
要观察键盘事件,请订阅键盘事件:-
import IQKeyboardNotification
class ViewController: UIViewController {
private let keyboard: IQKeyboardNotification = .init()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Subscribe
keyboard.subscribe(identifier: "YOUR_UNIQUE_IDENTIFIER") { event, frame in
print(frame)
// Write your own logic here based on event and keyboard frame
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Unsubscribe
keyboard.unsubscribe(identifier: "YOUR_UNIQUE_IDENTIFIER")
}
}
Iftekhar Qurashi hack.iftekhar@gmail.com
IQKeyboardNotification 在 MIT 许可证下可用。 有关更多信息,请参见 LICENSE 文件。