UITextView automatic scroll down

前端 未结 9 1696
遇见更好的自我
遇见更好的自我 2020-12-14 15:33

I have an UIView and I add a editable UITextView to it,

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(5, 5, 2         


        
相关标签:
9条回答
  • 2020-12-14 16:30

    Swift 2.2. It works for me

    func textViewDidChange(textView: UITextView) {
    
       let bottomOffset = CGPointMake(0, textView.contentSize.height - textView.bounds.size.height)
       textView.setContentOffset(bottomOffset, animated: true)
    }
    
    0 讨论(0)
  • 2020-12-14 16:32

    Just figured out that you must use a length > 0. Ie

    NSRange range = NSMakeRange(textView.text.length - 1, 1);
    [textView scrollRangeToVisible:range];
    

    Worked for me anyway.

    0 讨论(0)
  • 2020-12-14 16:34

    Use contentOffset, it will automatically scroll to down

    textView.contentOffset = CGPointMake(0, textView.contentSize.height - textView.frame.size.height);
    
    0 讨论(0)
提交回复
热议问题