OC - 点击空白处隐藏键盘

IQKeyboardManager是肯定要加的了,其次就是点击空白处隐藏键盘。

在view中重写touchesBegan方法

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {    

[userNameTextField resignFirstResponder];    

[passwordTextField resignFirstResponder];

}

其次点击回车按钮的方法

- (BOOL)textFieldShouldReturn:(UITextField *)textField {

    if(textField == userNameTextField) {

        [userNameTextField resignFirstResponder];        

        [passwordTextField becomeFirstResponder];    

    }    

    else {

        [passwordTextField resignFirstResponder];

        [self loginButtonPressed:nil];    

    }

    return true;

}

你可能感兴趣的:(OC - 点击空白处隐藏键盘)