Why is UITextField animating on resignFirstResponder?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 23:30:13
cnu

The problem seems to be that you are executing the piece of code in

-(void)keyboardWillShow:(NSNotification *)sender

even if the keyboard is already active, which leads to some distortion.

A small work around would be to check if the keyboard is already active before adjusting the frames, as below

bool isKeyboardActive = false;

-(void)keyboardWillHide:(NSNotification *)sender

{

    self.boxBottomConstraint.constant = 0;
    [self.view layoutIfNeeded];
    isKeyboardActive = false;
}


-(void)keyboardWillShow:(NSNotification *)sender

{

    if (!isKeyboardActive) {
        CGRect frame = [sender.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
        CGRect newFrame = [self.view convertRect:frame fromView:[[UIApplication sharedApplication] delegate].window];
        self.boxBottomConstraint.constant = CGRectGetHeight(newFrame);
        [self.view layoutIfNeeded];
        isKeyboardActive = true;
    }
}
aman.sood

Try this

 - (void)textFieldDidEndEditing:(UITextField *)textField
 {
    [textField layoutIfNeeded]; 
 }

Which I guess should resolve your issue. Got some similar post at UITextField: When beginning input, textfield bounces up, and then bounces down

IOS8 Text in TextField Bounces on Focus

Let me know if still we have issue

Try wrapping your code in this

[UIView performWithoutAnimation:^{
// Changes we don't want animated here
}];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!