1.textview有 什么的就算不明白,我的文本最后一个字符是 ,结果我死活算不对,最后发现了==!
NSString * str = [_messageModels[indexPath.row].text stringByReplacingOccurrencesOfString:@" " withString:@""];
2.textview用sizeThatFits算比较准确
3.textview加事件之前写了
4.高度自适应,需求是写三行以内撑高,三行以上变成滚动
=====重点是三行以内要把滚动关掉要不然自己去自适应了总是上下不平均而且还是偶现
=====用sizeThatFits算比较准确,用contentSize不准,网上说准但是我没用好可能我的用法有问题
=====跳出@人员列表,结果回来他就不自己添加@这个字符了,我就手动加上去了,很奇怪,明明return YES了。
-(void)textViewDidChange:(UITextView *)textView{
if (textView.text.length>0) {
self.placehoderLabel.hidden = YES;
}else{
self.placehoderLabel.hidden = NO;
}
CGSize size = [textView sizeThatFits:CGSizeMake(textView.frame.size.width, 1000)];
if (size.height>85) {
self.txtMessageBox.scrollEnabled = YES;
return;
}
self.txtMessageBox.scrollEnabled = NO;
if(_delegate)
[_delegate changeInputViewHeight:size.height+15];我是外部调用的把它撑开
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
if ([text isEqualToString:@"@"]) {
self.txtMessageBox.text = [self.txtMessageBox.text stringByAppendingString:@"@"];
self.placehoderLabel.hidden = YES;
AllMembersViewController * allvc = [[AllMembersViewController alloc]init];
allvc.roomId = [self.roomId longLongValue];
allvc.delegate = self;
_isAddRemindView = YES;
[self presentViewController:allvc animated:YES completion:nil];
}
if ([text isEqualToString:@" "]) {
if (textView.text&&[[textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]>0) {
if(_delegate) {
[_delegate sendTextMessage:[textView text]withRemind:self.remindArray];
}
[textView setText:@""];
[self.remindArray removeAllObjects];
self.placehoderLabel.hidden = NO;
[self textViewDidChange:self.txtMessageBox];
[self setTextDraft];
}
return NO;
}
return YES;
}
5.未完待续。。。。。