MFMailComposeViewController Keyboard Issue

拟墨画扇 提交于 2019-11-30 03:12:50

问题


How do i dismiss the keyboard without pressing the Send or Cancel button in MFMailComposeViewController?!

Thanks for any help.


回答1:


Can you try this.

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

hope this helps....




回答2:


I experienced a similar problem: For some reason iOS does not dismiss the Keyboard of a MFMailComposeViewController when the application enters background (the dismiss happens when the application becomes active again). However iOS dismisses the keyboard if the first responder is a simple element (e.g. textview). Calling resignFirstResponder did not work for me in this particular case. Because I switch windows on applicationBecomeActive (to show a login screen) I ended up having multiple keyboards above each other (the one on the top not working). I found a simple workaround to dismiss the keyboard of an MFMailComposeViewController when the application resigns active:

- (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
}

This will implicitly resign the first responder if we have any viewController that is currently beeing presented.




回答3:


While you probably can do it by finding whichever view is the first responder and calling resignFirstResponder on it (unless you're on iPad and MFMailComposeViewController uses UIModalPresentationFormSheet), Apple might reject your app for it. Quoth the documentation:

Important: The mail composition interface itself is not customizable and must not be modified by your application.

This could easily be construed to include the behavior of the keyboard.



来源:https://stackoverflow.com/questions/4872565/mfmailcomposeviewcontroller-keyboard-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!