9

我如何消除鍵盤沒有按下發送或MFMailComposeViewController取消按鈕?MFMailComposeViewController鍵盤問題

感謝您的任何幫助。

+3

出於好奇,你爲什麼要? – PengOne 2011-06-13 03:06:00

+0

由於使用了7KV7建議的代碼,我的應用程序今天被拒絕。只是爲了讓你知道不要在應用商店的應用中使用它。 – 2011-10-05 20:00:16

回答

6

你可以試試這個。

UIWindow* keyWindow = [[UIApplication sharedApplication] keyWindow]; 
UIView* firstResponder = [keyWindow performSelector:@selector(firstResponder)]; 
[firstResponder resignFirstResponder]; 

希望這有助於....

+4

注意的UIWindow的`firstResponder`方法是私有的API,因此使用它容易得到蘋果拒絕您的應用程序,如果你將其提交到App Store,並承擔停止,恕不另行通知,如果在未來的iOS版本一起工作。 – Anomie 2011-06-08 10:24:16

2

雖然你也許可以通過發現哪個視圖是第一響應者,並呼籲它resignFirstResponder(除非你的iPad和MFMailComposeViewController使用UIModalPresentationFormSheet)做到這一點,蘋果可能會拒絕你的應用程序。答曰the documentation

重要:郵件撰寫界面本身不是定製的,不得通過您的應用程序進行修改。

這很容易被理解爲包括鍵盤的行爲。

3

我經歷了類似的問題:由於某些原因,當應用程序進入後臺iOS不辭退MFMailComposeViewController的鍵盤(在解僱當應用程序被激活再次發生)。但是,如果第一個響應者是一個簡單元素(例如textview),則iOS會關閉鍵盤。在這種特殊情況下,調用resignFirstResponder對我無效。 因爲我在applicationBecomeActive上切換窗口(顯示一個登錄屏幕),所以我最終得到了多個鍵盤(頂部的鍵盤不工作)。 我發現了一個簡單的解決方法在應用程序主動辭職辭退的MFMailComposeViewController的鍵盤:

- (void)applicationWillResignActive:(UIApplication *)application 
{ 
    // Workaround: MFMailComposeViewController does not dismiss keyboard when application enters background 
    UITextView *dummyTextView = [[UITextView alloc] init]; 
    [self.window.rootViewController.presentedViewController.view addSubview:dummyTextView]; 
    [dummyTextView becomeFirstResponder]; 
    [dummyTextView resignFirstResponder]; 
    [dummyTextView removeFromSuperview]; 
    // End of workaround 
} 

這將暗示辭職第一響應者,如果我們有當前beeing提出任何的viewController。