调用方法 AFTER textFieldShouldReturn



我想在键盘关闭后调用我的登录方法 - 因为我想开始动画并将 UIView alpha 更改为 0.5,直到响应。

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == self.passwordText){
//hide the keyboard
[theTextField resignFirstResponder];
[self validateCredentialsRemotely];
}else{
[self.passwordText becomeFirstResponder];
}
return YES;
}

在调用方法validateCredentialsRemotely之前,键盘未被关闭,并且在显示键盘时屏幕冻结。我希望先将其消除,然后再调用该方法。

使用此通知。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

在键盘将隐藏方法调用你的验证凭据远程方法,这可能会解决你的第一个问题

试试这个!

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == self.passwordText){
//hide the keyboard
[theTextField resignFirstResponder];
[self performSelector:@selector(doAnim) withObject:nil afterDelay:0];
}else{
[self.passwordText becomeFirstResponder];
}
return YES;
}
- (void)doAnim {
//start animation
self.view.alpha =0.5;
[activityWheel startAnimating];
//validate user
[self validateCredentialsRemotely];
//end animation
[activityWheel stopAnimating];
self.view.alpha =1;
}

最新更新