Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard hides TabBar

I am working in a TabBar app. In one view there is a UISearchBar and, when is pressed, the keyboard appears.

The problem is that the keyboard hides the tabbar.

Do you know how to solve it?

like image 432
JAA Avatar asked Mar 11 '11 11:03

JAA


People also ask

How do I hide the navigation bar react?

To hide the navigation navbar with React Native, we set the screenOptions. headerShown option to false .

How do I hide the tab bar?

Hide Tabs Using F11 Shortcut Pressing the F11 button on your keyboard makes Google Chrome go into full-screen view. This, in turn, hides the address bar and all the tabs from the toolbar menu.


1 Answers

It's been a while since this was asked, but for the sake of documentation, here it goes: First, subscribe to the NSNotificationCenter to receive the keyboard notification:

-(void) viewWillAppear:(BOOL)animated
{
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillToggle:)
                                             name:UIKeyboardWillShowNotification object:nil];
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillToggle:)
                                             name:UIKeyboardWillHideNotification object:nil];
}

don't forget to unsubscribe

- (void)viewWillDisappear:(BOOL)animated 
{
 [self.view endEditing:YES];
 [super viewWillDisappear:animated];
 [[NSNotificationCenter defaultCenter] removeObserver:self
                                                name:UIKeyboardWillShowNotification object:nil];
 [[NSNotificationCenter defaultCenter] removeObserver:self
                                                name:UIKeyboardWillHideNotification  object:nil];
}

Then implement the function that will be called by the notification center:

- (void) keyboardWillToggle:(NSNotification *)aNotification
{
 CGRect frame = [[[self tabBarController] tabBar] frame];
 CGRect keyboard = [[aNotification.userInfo valueForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
 frame.origin.y = keyboard.origin.y - frame.size.height;
 [UIView animateWithDuration:[[aNotification.userInfo valueForKey:@"UIKeyboardAnimationDurationUserInfoKey"] floatValue] animations:^
 {
     [[[self tabBarController] tabBar] setFrame:frame];
 }];

This will animate the TabBar at the keyboard's pace and keep it on top.

like image 136
Agustin Avatar answered Sep 27 '22 22:09

Agustin