From Google翻译:Keyboard and TextField
你好,当我点击文本字段时,我对选取器视图做了一些修改。
当我从文本字段导航到文本字段而未触及“完成”按钮时,我转到包含选取器视图的文本字段,并且按下完成后,滚动视图不会恢复到其原始大小。
你知道如何取悦吗?
原文:
卓悦,lorsque JE集团河畔的联合国文本字段,J'AI FAIS quelques修改倒qu'un选择器视图apparaisse。
Quand je navigue de text field en text field sans toucher sur la touche“Terminé”et que je je rend dans un text field qui contient un picker view et que la,j'appuis surterminé,le scroll view ne remand pas sa taille motle。
Savez vous评论faire s'il vousplaît?
Voici周一代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[ScrollView setContentSize:CGSizeMake(320, 974)];
[ScrollView setScrollEnabled:YES];
//on abonne notre instance aux notifications du clavier lorsqu'il apparaît et lorsqu'il disparait
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)aNotification {
//si le clavier est déjà présent on ne fait rien
if (keyboardIsShown) {
return;
}
if (nom.editing == YES)
{
//on récupère la taille du clavier
NSDictionary* info = [aNotification userInfo];
CGRect _keyboardEndFrame;
[[info valueForKey:UIKeyboardFrameEndUserInfoKey] getValue:&_keyboardEndFrame];
CGSize keyboardSize = _keyboardEndFrame.size;
//on crée une nouvelle frame pour la scrollView
CGRect viewFrame = self.ScrollView.frame;
viewFrame.size.height -= keyboardSize.height;
//on redimensionne la scrollView dans une animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3];
[self.ScrollView setFrame:viewFrame];
[UIView commitAnimations];
//on scroll jusqu'au champs texte en cours d'édition
CGRect textFieldRect = nom.frame;
[self.ScrollView scrollRectToVisible:textFieldRect animated:YES];
//on enregistre l'état actuel du clavier
keyboardIsShown = YES;
}
else if (dateVol.editing == YES)
{
//on récupère la taille du clavier
NSDictionary* info = [aNotification userInfo];
CGRect _keyboardEndFrame;
[[info valueForKey:UIKeyboardFrameEndUserInfoKey] getValue:&_keyboardEndFrame];
CGSize keyboardSize = _keyboardEndFrame.size;
//on crée une nouvelle frame pour la scrollView
CGRect viewFrame = self.ScrollView.frame;
viewFrame.size.height -= keyboardSize.height;
//on redimensionne la scrollView dans une animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3];
[self.ScrollView setFrame:viewFrame];
[UIView commitAnimations];
//on scroll jusqu'au champs texte en cours d'édition
CGRect textFieldRect = prenom.frame;
[self.ScrollView scrollRectToVisible:textFieldRect animated:YES];
//on enregistre l'état actuel du clavier
keyboardIsShown = YES;
}
}
//méthode appelée lorsque le clavier disparaît (on quitte l'édition d'un champs texte)
- (void)keyboardWillHide:(NSNotification *)aNotification {
if (nom.editing == YES || dateVol.editing == YES)
{
//get the size of the keyboard
NSDictionary* info = [aNotification userInfo];
CGRect _keyboardEndFrame;
[[info valueForKey:UIKeyboardFrameEndUserInfoKey] getValue:&_keyboardEndFrame];
CGSize keyboardSize = _keyboardEndFrame.size;
//resize the scroll view
CGRect viewFrame = self.ScrollView.frame;
viewFrame.size.height += keyboardSize.height;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3];
[self.ScrollView setFrame:viewFrame];
[UIView commitAnimations];
keyboardIsShown = NO;
}
}
你能用英文发表你的问题吗? –
Anglais s'il vousplaît(英语请)。 – rmaddy
要么你正在做一件非常奇怪的事情,把'UIPickerView'放到'UITextField'中,否则Google Translate不能很好地工作。我假设后者,并问我的朋友是否可以帮忙。 – WolfLink