自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
你在模擬器上檢查?如果是,你使用外部鍵盤? –