自iOS 8以来,表单中的UITextFields表现得非常奇怪。如果我点击另一个文本字段或按下键盘上的Tab键,输入的文字将向上移动,然后快速重新出现。它发生在每次视图加载后,以及之后的每一次。为什么UITextField在resignFirstResponder上动画?
它看起来像这样:
我的代码如下所示:
#pragma mark - <UITextFieldDelegate>
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == self.passwordTextField) {
[self loginButtonClicked:nil];
} else if (textField == self.emailTextField) {
[self.passwordTextField becomeFirstResponder];
}
return YES;
}
编辑:
它看起来像这个问题由我的键盘听众造成的:
[[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];
}
它为我工作得很好。你在使用UITextField的第三方子类吗? –
不,我不知道。这是一个普通的'UITextField',我不使用第三方库或其他。 – gklka
你在模拟器上检查?如果是,你使用外部键盘? –