Da iOS 8, i campi UIText in una forma si comportano in modo molto strano. Se clicco su un altro campo di testo o premo Tab sulla tastiera, il testo inserito si anima verso l'alto e poi riappare rapidamente. Succede ogni volta dopo che la vista è stata caricata e ogni tanto in seguito.Perché UITextField si anima su resignFirstResponder?
Ecco come si presenta:
Il mio codice è simile al seguente:
#pragma mark - <UITextFieldDelegate>
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == self.passwordTextField) {
[self loginButtonClicked:nil];
} else if (textField == self.emailTextField) {
[self.passwordTextField becomeFirstResponder];
}
return YES;
}
EDIT:
Sembra che questo problema è causato dai miei ascoltatori della tastiera:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- (void)keyboardWillHide:(NSNotification *)sender
{
self.loginBoxBottomLayoutConstraint.constant = 0;
[self.view layoutIfNeeded];
}
- (void)keyboardWillShow:(NSNotification *)sender
{
CGRect frame = [sender.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect newFrame = [self.view convertRect:frame fromView:[[UIApplication sharedApplication] delegate].window];
self.loginBoxBottomLayoutConstraint.constant = CGRectGetHeight(newFrame);
[self.view layoutIfNeeded];
}
sua funziona bene per me. Stai usando qualche sottoclasse di terze parti di UITextField? –
No, non lo faccio. È un semplice 'UITextField', e io non uso nessuna libreria di terze parti o altro. – gklka
Stai controllando su Simulator? Se sì stai usando una tastiera esterna? –