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制作动画,并将其保持在最顶层.
| 归档时间: |
|
| 查看次数: |
3616 次 |
| 最近记录: |