nahive / SnapKit-Keyboard

Handle updating SnapKit constraints semi-automatically when keyboard is shown/hidden 📱

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SnapKit-Keyboard

Handling keyboard appearing/disappearing in SnapKit.

How to use it?

In viewDidLoad or other initializing place in code call view.registerAutomaticKeyboardConstraints().

override func viewDidLoad(){
    view.registerAutomaticKeyboardConstraints()
}

Then while adding constraints add .keyboard(false, in: view) to constraints in make or remake to deactivate them automatically when keyboard appears.

topView.snp.makeConstraints { (make) in
   make.left.equalTo(view.snp.left)
   make.right.equalTo(view.snp.right)
   make.top.equalTo(view.snp.top).keyboard(false, in: view)
   make.height.equalTo(100)
}        

As for constraints you want to keep/install when keyboard appears call .keyboard(true, in: view) on them in .snp.prepareConstraints.

topView.snp.prepareConstraints { (make) in
   make.bottom.equalTo(view.snp.top).keyboard(true, in: view)
}

If your view is launching with keyboard already shown - you should switch .makeConstraints with .prepareConstraints so that .makeConstraints constains code for keyboard shown constraints and .prepareConstraints should in that case contain code for keyboard hidden.

About

Handle updating SnapKit constraints semi-automatically when keyboard is shown/hidden 📱

License:The Unlicense


Languages

Language:Swift 73.1%Language:Objective-C 26.9%