2015-10-09 95 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];婁代碼行解決問題