直接上代码吧
通过改变的字符,判断是否存在回车
swift版
func textView(textView: UITextView,shouldChangeTextInRange range: NSRange,replacementText text: String) -> Bool {
if text == "\n"
{
self.inputView.resignFirstResponder()
return false
}
return true
}
OC版
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if ([text isEqualToString:@"\n"]) {
[self.inputView resignFirstResponder];
return NO;
}
return YES;
}