Keyboard hides TabBar

穿精又带淫゛_ 提交于 2019-11-29 09:16:43

问题


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?


回答1:


To my knowledge you cant move keyboard .. so try to use transformation to move the tab-bar above keyboard

Taken from here

Another link




回答2:


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.




回答3:


I solved this by showing a custom keyboard instead of the native uikeyboard.

Download the sample project from this github link.

customize the keypad to the desired native keypad either it is number or words.

Then place the uibuttons below the custom keypad with tabbar controllers like image like below image. Try this(future visitors), it may solve the issue.



来源:https://stackoverflow.com/questions/5272267/keyboard-hides-tabbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!