美文网首页
iOS 文字 逐字显示

iOS 文字 逐字显示

作者: 小白lf | 来源:发表于2023-11-13 15:04 被阅读0次

    class ViewController1: BaseViewController {
    var textView = UITextView.init()
    var poem = [("Test ", 0.2), ("my ", 0.2), ("core ", 0.2), ("just ", 0.2), ("like ", 0.2), ("before", 0.2)]

    func display(poem: [(word: String, delay: TimeInterval)]) {
        guard let first = poem.first else { return }
    
        UIView.transition(with: textView,
                          duration: first.delay,
                          options: .transitionCrossDissolve,
                          animations: { self.textView.text.append(first.word) },
                          completion: nil)
    
        DispatchQueue.main.asyncAfter(deadline: .now() + first.delay) {
            self.display(poem: Array(poem.dropFirst()))
        }
    }
    

    }

    相关文章

      网友评论

          本文标题:iOS 文字 逐字显示

          本文链接:https://www.haomeiwen.com/subject/nzkdwdtx.html