私のiPhoneアプリで。受信者をMFMailComposerView
クリックすると、キーボードが表示されます。キーボードのリターンキーをクリックした後。しかし、キーボードは消えません。
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];
ただし、これをアプリで使用する場合、UIWindowのfirstResponderメソッドはプライベートAPIであるため、Appleは確実にアプリを拒否します。
参照:SO
于 2013-01-04T09:30:21.673 に答える