简体   繁体   English

如何在UITextView中像提词提示器中快速滚动文本?

[英]How to scroll text in UITextView like teleprompter in swift?

I want to scroll my text like teleprompter scroll. 我想像提词提示滚动一样滚动文本。 I've read about UIDynamicAnimation but not clear with UITextView for multiple lines. 我已经读过有关UIDynamicAnimation但不清楚UITextView是否包含多行内容。

Appreciate your suggestions or code snippets to achieve this. 感谢您的建议或代码片段以实现此目的。

Using a recursive method we could animate each row scroll using UIView.animate(withDuration:animations:completed) till we reach the end of the textView. 使用递归方法,我们可以使用UIView.animate(withDuration:animations:completed)每一行滚动设置UIView.animate(withDuration:animations:completed)直到到达UIView.animate(withDuration:animations:completed)的末尾。

func animateRowWith(duration: TimeInterval, rowHeight: CGFloat) {
    if self.textView.contentOffset.y < self.textView.contentSize.height - self.textView.frame.size.height {
        UIView.animate(withDuration: duration, animations: {
            self.textView.contentOffset = CGPoint(x: self.textView.contentOffset.x, y: self.textView.contentOffset.y + rowHeight)
        }) { (_) in
            self.animateRowWith(duration: duration, rowHeight: rowHeight)
        }
    }
}

calling it: 称之为:

animateRowWith(duration: 1.0, rowHeight: self.textView.font?.lineHeight ?? 0) . animateRowWith(duration: 1.0, rowHeight: self.textView.font?.lineHeight ?? 0)

Note that you will have a delay after each row has scrolled. 请注意,每行滚动后会有延迟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM