KeyboardDodger 版本 2.0.0

KeyboardDodger 版本 2.0.0

Daniel ClellandSimon Cook 维护。



  • 作者:
  • Daniel Clelland

KeyboardDodger

KeyboardDodger 是一个 iOS Cocoapod,它使用约束将视图从屏幕键盘移开。

安装

pod 'KeyboardDodger', '~> 1.0'

使用

KeyboardDodger 将其连接到一个视图和视图底部的约束,并通过操作该约束来保持其不在屏幕键盘的路径上。

一个示例实现

class ViewController: UIViewController {

    var bottomConstraint: NSLayoutConstraint?

    var keyboardDodger: KeyboardDodger?

    override func viewDidLoad() {
        super.viewDidLoad()

        if let bottomConstraint = bottomConstraint {
            keyboardDodger = KeyboardDodger(view: view, constraint: bottomConstraint, delegate: self)
        }
    }

}

extension ViewController: KeyboardDodgerDelegate {
    
    func keyboardDodger(_ keyboardDodger: KeyboardDodger, willUpdateConstraintWith transition: KeyboardDodgerTransition) {
        print("Keyboard dodger will update constraint")
    }
    
    func keyboardDodger(_ keyboardDodger: KeyboardDodger, didUpdateConstraintWith transition: KeyboardDodgerTransition) {
        print("Keyboard dodger did update constraint")
    }
    
    func keyboardDodger(_ keyboardDodger: KeyboardDodger, willResetConstraintWith transition: KeyboardDodgerTransition) {
        print("Keyboard dodger will reset constraint")
    }
    
    func keyboardDodger(_ keyboardDodger: KeyboardDodger, didResetConstraintWith transition: KeyboardDodgerTransition) {
        print("Keyboard dodger did reset constraint")
    }

}