evgenyneu / UnderKeyboard

An iOS libary for moving content from under the keyboard.
MIT License
128 stars 22 forks source link

Is it possible to only toggle UnderKeyBoard on certain text fields? #1

Closed kiwo12345 closed 7 years ago

kiwo12345 commented 8 years ago

Can I use this inside eg: textFieldDidBeginEditing() ?

I only want to toggle UnderKeyBoard on certain textFields and also use different contraints depending on what text field is being edited

evgenyneu commented 8 years ago

What you can do is to detect when the keyboard appears/disappears and modify your constraints manually. It is described in "Using keyboard observer directly" section of the readme:

https://github.com/exchangegroup/UnderKeyboard#using-keyboard-observer-directly

kiwo12345 commented 8 years ago

Thanks, and also thanks for sharing this library!

Like this?:

let keyboardObserver = UnderKeyboardObserver()

override func viewDidLoad() { super.viewDidLoad() keyboardObserver.start()

// Called before the keyboard is animated keyboardObserver.willAnimateKeyboard = { height in myConstraint.constant = MyCustomHeight }

// Called inside the UIView.animateWithDuration animations block keyboardObserver.animateKeyboard = { height in view.layoutIfNeeded() } }

Does this mean I only use UnderKeyboardObserver() instead of UnderKeyboardLayoutConstraint() ?

evgenyneu commented 8 years ago

Yes, this is the code you can use. The implementation inside the two closures specific will be specific to your app.

And yes - in this case you do not need to use UnderKeyboardLayoutConstraint class as you will be manipulating your auto layout constraints yourself.

evgenyneu commented 7 years ago

Closing the issue. Feel free to reopen if needed.