我想在键盘被解除后调用我的登录方法 - 因为我想开始动画并将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
之前,键盘没有被解除,并且在显示键盘时屏幕会冻结。我希望先被解雇,然后调用方法。
答案 0 :(得分:2)
使用此通知..
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
在keyboardWillHide方法中调用validateCredentialsRemotely方法,这可能会解决您的第一个问题
答案 1 :(得分:1)
试试这个!
- (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;
}