我在這裏看了很多帖子關於這個話題,但我沒能找到一個回答我的問題,所以,希望你不會覺得無聊關於另一UIKeyboard後:-)UIKeyboardWillHide不會觸發
在我的視圖控制器的實現我添加了self
作爲兩個通知UIKeyboardWillShowNotification
和UIKeyboardWillHideNotification
的觀察者,通過選擇器keyboardWillShow:
和keyboardWillHide:
來處理通知。當我觸摸UITextField
時,將調用keyboardWillShow:
方法,但當按下「完成」按鈕(即關閉鍵盤)時,不會調用keyboardWillHide:
方法。
真的,我想讓我的UITextField
顯示鍵盤右下方的「隱藏按鈕」,但我無法找到正確的鍵盤類型。也許我需要將textfield retuntype設置爲「...完成」。這樣我看到「返回」鍵變成「完成」。
因此,我設置了一個工具欄爲我的UITextField
的inputAccessoryView
,所以現在我可以用「完成」按鈕顯示上面帶有工具欄的標準鍵盤。當用戶觸摸該按鈕時,我用resignFirstResponder
方法隱藏鍵盤。
奇怪的是,當我打電話給resignFirstResponder
時,UIKeyboardWillHideNotification
沒有發佈;至少不調用keyboardWillHide:
方法。
你對我建議什麼?我真的想用小箭頭來顯示一個帶有向下箭頭的小鍵盤來隱藏鍵盤,但是這個解決方案可能是正確的,但是我想調整視圖的大小,並且爲此我需要觀察者UIKeyboardWillHideNotification
。
非常感謝您的幫助......
(增加:)
在viewDidLoad
:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:[[self view] window]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:[[self view] window]];
我把這些聲明從 「你」 的帖子:-)之一,但willShow的作品...
UIToolbar
中的「完成」按鈕的動作被分配爲我的文本fi的inputAccessoryView
現場是:
-(void)keyboardDone {
[msgTextField resignFirstResponder];
閉合: 行!當一個開發商是愚蠢的......這是愚蠢的:-) :-)
這是我糾正willHide方法:
-(void)keyboardWillHide:(NSNotification*)n {
NSDictionary* userInfo;
CGSize keyboardSize;
CGRect viewFrame;
/* This was the bad guy :) I forgot to delete it
* after I previously copied the willShow method that
* checks if keyboard is already shown (if so returns).
*
* if(keyboardIsShown)
* return;
*/
userInfo = [n userInfo];
keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
viewFrame = [[self scrollView] frame];
viewFrame.size.height += (keyboardSize.height - TABBAR_HEIGHT);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];
[[self scrollView] setFrame:viewFrame];
[UIView commitAnimations];
keyboardIsShown = NO;
NSLog(@"HIDE\n");
}
所有我想感謝大家這個沒用上班第一幫助我。我想給你一些觀點,所以我會嘗試爲每個答案提出一個「興趣點」,但是我需要選擇正確的一個......難點部分...... :-)
Excuse我再次...我真的沒有看到if()語句...
您可以發佈您的觀察員和方法? – Bot
另外,這是在一個模式/提出的VC? – MishieMoo
這是一個tabbar應用程序的視圖... –