Programmatically check if iPhone keyboard is on screen or not

15,593

Basically, you want to add an NSNotificationCenter observer:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow) name:UIKeyboardDidShowNotification object:nil];
Share:
15,593
Mason
Author by

Mason

Updated on June 27, 2022

Comments

  • Mason
    Mason almost 2 years

    Possible Duplicate:
    How to programatically check whether a keyboard is present in iphone app?
    Detect if UIKeyBoard is Showing

    Is there a way to programmatically check if the iPhone's keyboard is on screen or not?

  • Mason
    Mason over 12 years
    I don't want it to necessarily call a function upon receiving the notification, though, I just want it to check before it adds a subview. It'll affect the frame of the subview.
  • Mason
    Mason over 12 years
    Oh wait, never mind. I can just change the value of a boolean. Thanks!
  • WrightsCS
    WrightsCS over 12 years
    You can set the selector to nil, but how else do you expect to know when it appears?