2

我想在键盘被关闭后调用我的登录方法 - 因为我想启动动画并将 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并且在显示键盘时屏幕会冻结。我希望它首先被解雇,然后调用该方法。

4

2 回答 2

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 方法,这可能会解决您的第一个问题

于 2012-12-20T12:51:27.583 回答
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;
}
于 2012-12-20T12:50:31.090 回答