iOS 点击键盘的return隐藏键盘

#pragma mark - UITextFieldDetegate


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

    

    [self.view endEditing:YES];

    return YES;

}


#pragma mark - UITextViewDelegate


- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

    if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车,即按下return

        //在这里做你响应return键的代码

        [self.remarksTFView resignFirstResponder];

        return NO; //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行

    }

    return YES;

}

你可能感兴趣的:(iOS,隐藏键盘)