- A View that can interact with keyboard events can change simultaneously with the height of the keyboard, simply and effectively solving the problem of the input box being blocked during text input.
- 一個能跟鍵盤事件互動的View,能與鍵盤高度同時做變化,簡單有效處理文字輸入時,輸入框被檔住的問題。
dependencies: [
.package(url: "https://github.com/William-Weng/WWKeyboardShadowView.git", .upToNextMajor(from: "1.0.0"))
]
函式 | 說明 |
---|---|
configure(target:keyboardConstraintHeight:) | 設定初始View相關參數 |
register() | 註冊鍵盤事件 |
unregister() | 解除鍵盤事件 |
import UIKit
import WWPrint
import WWKeyboardShadowView
final class ViewController: UIViewController {
@IBOutlet weak var keyboardShadowView: WWKeyboardShadowView!
@IBOutlet weak var shadowViewHeightConstraint: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
initSetting()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
view.endEditing(true)
}
}
extension ViewController: WWKeyboardShadowViewDelegate {
func keyboardWillChange(view: WWKeyboardShadowView, information: WWKeyboardShadowView.KeyboardInfomation) -> Bool {
wwPrint("keyboardWillChange")
return true
}
func keyboardDidChange(view: WWKeyboardShadowView) {
wwPrint("keyboardDidChange")
}
}
private extension ViewController {
func initSetting() {
keyboardShadowView.configure(target: self, keyboardConstraintHeight: shadowViewHeightConstraint)
keyboardShadowView.register()
}
}