2011-03-11 71 views
7

我在的TabBar應用工作。在一個視圖中有一個UISearchBar和,被按壓時,將顯示鍵盤。鍵盤隱藏的TabBar

問題是鍵盤隱藏了tabbar。

你知道如何解決它嗎?

+0

當用戶集中在輸入的東西在搜索欄中進行搜索,你爲什麼想要顯示的標籤? – Viraj 2011-03-11 11:26:11

+0

我還要說,是標準的行爲,你不應該改變這種狀況。 – 2011-03-11 11:37:26

+0

@Viraj我的評論希望這樣,是不是我的錯:P – JAA 2011-03-11 11:41:19

回答

0

據我所知,你不能移動鍵盤..所以儘量用轉型移動鍵盤上方

here

另一個link

13

兩者的標籤欄它已經有一段時間,因爲這是問,但爲了文件的緣故,這裏有: 首先,訂閱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

這應該是公認的答案。 – Sirens 2013-04-11 23:05:58

+0

我會重新使用'UIKeyboardDidChangeFrameNotification',否則你會遇到分離鍵盤的麻煩http://stackoverflow.com/a/13495680/296446。 – Robert 2013-06-18 13:49:11

0

我通過顯示自定義鍵盤而不是原生uikeyboard來解決此問題。

從此github鏈接下載示例項目。

將鍵盤自定義爲所需的原生鍵盤,無論是數字還是文字。

然後將uibutton放置在自定義鍵盤下方,並使用tabbar控制器,如下圖所示的圖像。試試這個(未來人次),它可以解決這個問題。

enter image description here