Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when keyboard is shown and hidden

How can I detect when the keyboard is shown and hidden from my application?

like image 613
user198725878 Avatar asked Dec 07 '10 07:12

user198725878


People also ask

How do I know if my keyboard is visible or not?

In the above code we have added windowsoftInputMode as stateAlwaysVisible. It is useful when edittext is request focused it will show keyboard. In the above output, when keyboard is displayed, it will show message as keyboard is showing. Click on a button to hide the keyboard.

How do I know if my keyboard is visible IOS?

If value of editCounter becomes 1 - this means that keyboard will appear (in case if you return YES). If editCounter > 1 - this means that keyboard is already visible and another UITextField holds the focus.

How do I make my keyboard always visible?

You must have an EditText in your layout and that need to extent EditText base class. then Override onKeyPreIme() method, and return True. Now your keyboard will be always visible and can't be dismissed by Back key.

How do I hide my keyboard when typing?

Tap the back button on your Android. It's the left-pointing arrow button at the bottom of the screen, either at the bottom-left or bottom-right corner. The keyboard is now hidden. The back button may be a physical button or on the touch screen. To bring the keyboard back into view, tap the typing area.


1 Answers

In the ViewDidLoad method of your class set up to listen for messages about the keyboard:

// Listen for keyboard appearances and disappearances [[NSNotificationCenter defaultCenter] addObserver:self                                           selector:@selector(keyboardDidShow:)                                              name:UIKeyboardDidShowNotification                                            object:nil];  [[NSNotificationCenter defaultCenter] addObserver:self                                          selector:@selector(keyboardDidHide:)                                              name:UIKeyboardDidHideNotification                                            object:nil]; 

Then in the methods you specify (in this case keyboardDidShow and keyboardDidHide) you can do something about it:

- (void)keyboardDidShow: (NSNotification *) notif{     // Do something here }  - (void)keyboardDidHide: (NSNotification *) notif{     // Do something here } 
like image 127
Matthew Frederick Avatar answered Sep 22 '22 15:09

Matthew Frederick