Swiftpack.co - Package - jorisvg/keyboard-observer

KeyboardObserver

This library makes working with keyboard notifications in iOS a lot easier, and type-safe.

Example

Create an instance of KeyboardObserver and hold a reference to it. Registering for notifications is as simple as passing a closure to the will... and did.. methods. The closure will receive the keyboard notification as a type-safe struct.

class ViewController: UIViewController {

    var observer: KeyboardObserver?
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        observer = KeyboardObserver()
            .willShow { notification in
                print("willShow \(notification)")
            }
            .didHide { notification in
                print("didHide \(notification)")
            }
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        observer = nil
        super.viewDidDisappear(animated)
    }
}

Github

link
Stars: 0

Dependencies

Used By

Total: 0