来自谷歌翻译:
您好,当我单击文本字段时,我对出现的选择器视图进行了一些修改。
当我在没有触摸“完成”按钮的情况下从文本字段导航到文本字段时,我转到了一个包含选择器视图的文本字段,并且按下完成后,滚动视图不会恢复到其原始大小。
你知道如何取悦吗?
原来的:
Bonjour, lorsque je clique sur un text field, j'ai fais quelques modify pour qu'un picker view apparaisse。
Quand je navigue de text field en text field sans toucher sur la touche "Terminé" et que je me rend dans un text field qui contient un picker view et que la, j'appuis sur terminé, le scroll view ne reprend pas sa taille initiale .
Savez vous comment faire s'il vous plaît ?
语音代码:
- (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;
}
}