In my iphone app. in MFMailComposerView
view when i am clicking to recepients then key board appears . After i am clicking return key in the key board. but key board not disappear.
问问题
313 次
2 回答
3
使用UIWindow
通知键盘,只需使用下面的代码来显示MFMailComposerViewController
..
- (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];
}
我从这个链接得到了一些代码..
于 2013-01-04T09:33:49.403 回答
0
您可以为此使用以下代码。
UIWindow *mainWin = [[UIApplication sharedApplication] keyWindow];
UIView *responder = [mainWin performSelector:@selector(firstResponder)];
[responder resignFirstResponder];
但是如果你在你的应用程序中使用它,Apple 肯定会拒绝你的应用程序,因为 UIWindow 的 firstResponder 方法是一个私有 API。
参考:所以
于 2013-01-04T09:30:21.673 回答