How do i dismiss the keyboard without pressing the Send or Cancel button in MFMailComposeViewController?!
Thanks for any help.
How do i dismiss the keyboard without pressing the Send or Cancel button in MFMailComposeViewController?!
Thanks for any help.
Can you try this.
UIWindow* keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView* firstResponder = [keyWindow performSelector:@selector(firstResponder)];
[firstResponder resignFirstResponder];
hope this helps....
firstResponder
method is a private API, so using it is liable to get Apple to reject your app if you submit it to the App Store and liable to stop working without notice in future versions if iOS. –
Suttles 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.
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.
© 2022 - 2024 — McMap. All rights reserved.