2015-10-09 49 views
1

我已经使用UITextView进行聊天,如截图所示。 enter image description here使用UITextView光标/滚动移动的问题

但问题是,如果我按键盘上的返回键,光标不会粘在UITextView边界的底部。我也使用以下代码:

- (void)textViewDidChange:(UITextView *)textView 
{ 
    if([textView contentSize].height <80.0) 
    { 
     CGFloat textHeight   = [self textHeightForTextView:textView]; 

     CGFloat newViewHeight = MAX(MIN(textHeight, 80.0), 33.0); 

     chatTxtHeightConstraint.constant = newViewHeight; 

     [textView scrollRangeToVisible:textView.selectedRange]; 
    } 
} 

任何解决方案?

回答

1

我已经写的chatTxtHeightConstraint.constant = newViewHeight;

- (void)textViewDidChange:(UITextView *)textView 
{ 
    if([textView contentSize].height <80.0) 
    { 
     CGFloat textHeight   = [self textHeightForTextView:textView]; 

     CGFloat newViewHeight = MAX(MIN(textHeight, 80.0), 33.0); 

     chatTxtHeightConstraint.constant = newViewHeight; 

     [textView layoutIfNeeded]; 
     [textView updateConstraints]; 

     [textView scrollRangeToVisible:textView.selectedRange]; 
    } 
} 
[textView layoutIfNeeded];[textView updateConstraints];娄代码行解决问题