[英]Keyboard hides TabBar
我正在使用TabBar应用程序。 在一个视图中有一个UISearchBar,当按下时,键盘出现。
问题是键盘隐藏了标签栏。
你知道怎么解决吗?
自从被问到这个问题已经有一段时间了,但是为了文档,这里有:首先,订阅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制作动画,并将其保持在最顶层。
我通过显示自定义键盘而不是原生的uikeyboard
键盘来解决这个问题。
从此github链接下载示例项目。
将键盘自定义为所需的本机键盘,无论是数字还是单词。
然后将uibutton放在自定义键盘下方,使用tabbar控制器,如下图所示的图像。 试试这个(未来的访客),它可能会解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.