键盘隐藏了TabBar

时间:2011-03-11 11:22:26

标签: iphone uitabbar tabbar iphone-softkeyboard

我正在使用TabBar应用。在一个视图中有一个UISearchBar,当按下时,键盘出现。

问题是键盘隐藏了标签栏。

你知道怎么解决吗?

3 个答案:

答案 0 :(得分:14)

自从被问到这个问题已经有一段时间了,但是为了记录,这里有: 首先,订阅NSNotificationCenter以接收键盘通知:

-(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];
}

不要忘记取消订阅

- (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];
}

然后实现通知中心将要调用的函数:

- (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];
 }];

这将以键盘的速度为TabBar设置动画并将其保持在最顶层。

答案 1 :(得分:0)

据我所知,你无法移动键盘..所以尝试使用转换来移动键盘上方的标签栏

取自here

另一个link

答案 2 :(得分:0)

我通过显示自定义键盘而不是原生uikeyboard解决了这个问题。

从此github链接下载示例项目。

将键盘自定义为所需的本机键盘,无论是数字还是单词。

然后将uibuttons放在自定义键盘下方,使用tabbar控制器,如下图所示。试试这个(未来的访问者),它可以解决问题。

enter image description here