I want to add an accessory to the keyboard called from UISearchBar. Since the UISearchBar does not implement this property, I just created a toolBar. After Apple's documentation on this issue, I decided to use the notification center not only to know when the keyboard is being called, but also to know the size of the keyboard, which varies depending on the orientation.
I followed the example in the documentation and, in the keyboardWasShown method, I invoke an animation that shows the toolBar on top of the keyboard. Something like that:
-(void)keyboardWasShown:(NSNotification*)aNotification { NSDictionary *info=[aNotification userInfo]; CGSize keyboardSize=[[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; NSLog(@"width: %.1f; heigth: %.1f", keyboardSize.width, keyboardSize.height ); [self showAccessoryView:keyboardSize.height]; }
and in the animation, I set the toolbar frame as follows:
self.auxiliaryKeyboardBar.frame=CGRectMake(0, self.view.frame.size.height-(44+kbh), self.view.frame.size.width, 44);
where 44 is the static top of the toolbar and kbh is the keyboard .size.heigth is passed from the above method.
The problem I am observing is that the keyboard size specified by the userInfo dictionary always refers to the portrait orientation. So, NSLog on portrait orientation:
width: 320.0; heigth: 216.0 width: 320.0; heigth: 216.0 , which is normal
but when I change the orientation to the landscape and I call the keyboard, NSLog looks like this:
width: 162.0; heigth: 480.0 width: 162.0; heigth: 480.0 , which takes the panel out of scope.
So, in the end, I added a condition before calling the animation, for example:
if ([self deviceIsPortrait]==YES) { [self showAccessoryView:keyboardSize.height]; }else if ([self deviceIsPortrait]==NO) { [self showAccessoryView:keyboardSize.width]; }
Now I am wondering if I am really doing something wrong, because I am following Apple's example to avoid depending on the keyboard hierarchy (like float), and I still had to add a conditional conditional expression.
Any ideas on what's going on here?