I am trying to offset UITextField whenever the keyboard is active, it works well, until I tried the Emoji-layout. Is there a way to detect the type of Keyboard-input, so I can find out the height-difference?
Thanks
Asked
Active
Viewed 521 times
1

Makaveli
- 309
- 1
- 3
- 9
-
You can use textfield delegates to detect if user has typed in an emoji. See [This question](http://stackoverflow.com/questions/14329110/detect-if-a-user-has-typed-an-emoji-character-in-uitextview). – NSNoob Apr 20 '16 at 06:09
-
@EICaptain I believe his issue is not to set the offset (He is doing that with simple text input). He is having trouble with handling emoji inputs due to which he wants to detect **type of input** from the keyboard – NSNoob Apr 20 '16 at 06:13
3 Answers
1
You can use the keyboard notifications
func getKeyboardHeight() {
let defaultCenter = NSNotificationCenter.defaultCenter()
defaultCenter.addObserver(self, selector: "keyboardWillChangeFrame:", name: UIKeyboardWillChangeFrameNotification, object: nil)
}
func keyboardWillChangeFrame(notification : NSNotification){
let keyboardFrame = (notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
let keyboardheight = keyboardFrame.height
}
And from the obtained height you can adjust the textfield's frame.
see the images.
image 1 before emoji is selected.
image 2 after emoji is selected
-
That's code to show keyboard appearance notification, not to detect whether emojis are being typed or not. If you have any queries regarding the question, Ask the OP via comments – NSNoob Apr 20 '16 at 06:10
-
1
-
He is already doing that. His issue is that he is having problems when user types in emoji due to which he wants to detect **Type of input** – NSNoob Apr 20 '16 at 06:12
1
Instead of using the UIKeyboardDidShowNotification/UIKeyboardDidHideNotification
observers, use the UIKeyboardWillChangeFrameNotification
observer, that is fired of each event: Keyboard hiding, keyboard showing and keyboard changing frame.
Like this:
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardAction), name: UIKeyboardWillChangeFrameNotification, object: nil)

Dejan Skledar
- 11,280
- 7
- 44
- 70
0
Thanks guys for your help, i have found the answer: I was using this line :
if let keyboardSize = (notifcation.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue().size{
I changed to the key-value of notifcation.userInfo to UIKeyboardFrameEndUserInfoKey, and that fixed the issue.

Makaveli
- 309
- 1
- 3
- 9