Well you can handle when the user swipe to show/hide the bar(prediction bar) of UIKeyboard,
First step
declare a keyboard notification in viewdidLoad()
and declare a global variable kbSize
float kbSize;
- (void)viewDidLoad
{
kbSize=0.0;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowNotification:) name:UIKeyboardWillShowNotification object:nil];
--- rest of your code here---
}
Second step
Now in keyboardWillShowNotification() method do the following
#pragma mark - Notifications
- (void)keyboardWillShowNotification:(NSNotification *)aNotification{
NSDictionary *infos = aNotification.userInfo;
NSValue *value = infos[UIKeyboardFrameEndUserInfoKey];
CGRect rawFrame = [value CGRectValue];
CGRect keyboardFrame = [self.view convertRect:rawFrame fromView:nil];
if(kbSize==0.0)
{
kbSize=keyboardFrame.size.height;
NSLog(@"prediction bar is visible");
}
else if(keyboardFrame.size.height<kbSize)
{
NSLog(@"prediction bar is not visible");
--- rest of your code here, how you want to change your view when bar is not visible ---
}
else
{
NSLog(@"prediction bar is visible");
--- rest of your code here, how you want to change your view when bar is visible ---
}
}
Conclusion:-
As keyboardWillShowNotification will always fire whenever the user does some editing with your text-fields or whenever user will swipe to hide or show the prediction bar.
So we just have to check the height of keyboard whenever keyboardWillShowNotification
will fire,so if the user swipe the bar to hide then automatically the keyboard height will decrease and we are already storing the height of keyboard in variable kbSize
, we just have to check whether current height of keyboard is less than then the stored kbSize
. So by this way we can check at runtime whether bar is visible or not or user swipe to hide the bar.