Iphone 如何在MFMailComposer视图中关闭键盘
在我的iphone应用程序中。在Iphone 如何在MFMailComposer视图中关闭键盘,iphone,objective-c,ios,Iphone,Objective C,Ios,在我的iphone应用程序中。在mfmailcomposereview视图中,当我单击收件人时,键盘出现。在我点击键盘上的返回键后。但键盘不会消失。您可以使用以下代码来实现此目的 UIWindow *mainWin = [[UIApplication sharedApplication] keyWindow]; UIView *responder = [mainWin performSelector:@selector(firstResponder)]; [responder resignFir
mfmailcomposereview
视图中,当我单击收件人时,键盘出现。在我点击键盘上的返回键后。但键盘不会消失。您可以使用以下代码来实现此目的
UIWindow *mainWin = [[UIApplication sharedApplication] keyWindow];
UIView *responder = [mainWin performSelector:@selector(firstResponder)];
[responder resignFirstResponder];
但如果你在应用程序中使用此方法,苹果肯定会拒绝你的应用程序,因为UIWindow的firstResponder方法是一个私有API。
参考资料:使用
ui窗口
通知键盘,只需使用下面的代码即可显示MFMailComposer视图控制器
- (IBAction)showMailController {
//Present mail controller on press of a button, set up notification of keyboard showing and hiding
[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
//... and so on
}
- (void)keyboardWillShow:(NSNotification *)note {
//Get view that's controlling the keyboard
UIWindow* keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView* firstResponder = [keyWindow performSelector:@selector(firstResponder)];
//set up dimensions of dismiss keyboard button and animate it into view, parameters are based on landscape orientation, the keyboard's dimensions and this button's specific dimensions
CGRect t;
[[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &t];
button.frame = CGRectMake(324,(290-t.size.height),156,37);
button.alpha = 0.0;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[[[[[firstResponder superview] superview] superview] superview] addSubview:button];
button.alpha = 1.0;
button.frame = CGRectMake(324,(253-t.size.height),156,37);
[UIView commitAnimations];
}
- (IBAction)dismissKeyboardInMailView {
//this is what gets called when the dismiss keyboard button is pressed
UIWindow* keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView* firstResponder = [keyWindow performSelector:@selector(firstResponder)];
[firstResponder resignFirstResponder];
}
- (void)keyboardWillHide:(NSNotification *)note {
//hide button here
[button removeFromSuperview];
}
我从这个链接得到了一些代码
不,键盘永远不会因为递归响应程序链攻击而消失,这在iOS 6之前可能有效,但现在邮件控制器是远程的,我绝对不能建议你尝试远程退出它的第一响应者。我认为return键在MFMailComposer视图中从一个textfield移动到另一个textfield。当最后一个textfield返回时。不要对与Xcode无关的问题使用Xcode标记!请将副本答案的atlist链接放在下面:-@NitinGohel:上面的解雇代码是什么?它与中使用的代码完全相同