键盘隐藏了TabBar

JAA*_*JAA 8 iphone tabbar uitabbar iphone-softkeyboard

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

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

你知道怎么解决吗?

小智 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];
}
Run Code Online (Sandbox Code Playgroud)

别忘了取消订阅

- (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];
}
Run Code Online (Sandbox Code Playgroud)

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

- (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];
 }];
Run Code Online (Sandbox Code Playgroud)

这将以键盘的速度为TabBar制作动画,并将其保持在最顶层.


vis*_*kh7 -1

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

取自这里

另一个链接