【问题标题】:UITextView text - animate text from top to bottomUITextView text - 从上到下动画文本
【发布时间】:2017-09-07 12:02:28
【问题描述】:

我正在使用UITextView。我想用动画从上到下自动滚动 textview 的文本一次。我怎样才能做到这一点?

【问题讨论】:

  • 请检查我的回答。

标签: ios objective-c animation uitextview


【解决方案1】:

您应该为UITextViewcontentOffset 属性设置动画。

Objective-C

[UIView animateWithDuration:{duration} animations:^{
    [textView setContentOffset:CGPointMake(0, textView.contentSize.height - textView.frame.size.height)];
}]

斯威夫特

UIView.animate(withDuration: {duration}) {
    textView.setContentOffset(CGPoint(x: 0, y: textView.contentSize.height - textView.frame.height), animated: false)
}

【讨论】:

    【解决方案2】:

    试试这个

     if(textView.text.length > 0 ) {
        NSRange bottom = NSMakeRange(textView.text.length -1, 1);
        [textView scrollRangeToVisible:bottom];
     }
    

    【讨论】:

      【解决方案3】:

      试试这个:

      斯威夫特:

      let range = NSMakeRange(textView.text.characters.count - 1, 0)
      textView.scrollRangeToVisible(range)
      

      目标 C:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-13
        • 1970-01-01
        相关资源
        最近更新 更多