解决方法
真的很喜欢这个灵感.还有两种方法可以将其添加到您的应用中:
1)这是我为您的实例创建的代码:
导入UIKit
1)这是我为您的实例创建的代码:
导入UIKit
class ViewController: UIViewController { let listOfRandomLetters = ["@","%","*","^","1","2","3"," "," "] var textNeedDisplaying = ["String","Other Person","Sample","String","Sample"] var newList: [String] = [] var incrementer = 0 var internalTimer: Timer? var timer: Timer? var mainTimer: Timer? @IBOutlet weak var animatingLabel: UILabel! override func viewDidAppear(_ animated: Bool) { schedule() } func schedule() { //Main Timer interval usually adds up the other two intervals self.mainTimer = Timer.scheduledTimer(withTimeInterval: 1,repeats: true,block: { _ in //Play around with the time Intervals self.internalTimer = Timer.scheduledTimer(withTimeInterval: 0.1,block: { _ in for _ in 0...arc4random_uniform(UInt32(10)) + 1 { let randomNumber = arc4random_uniform(UInt32(self.listOfRandomLetters.count - 1)) self.newList.append(self.listOfRandomLetters[Int(randomNumber)]) } self.animatingLabel.text = self.newList.joined() self.newList.removeAll() }) //Play around with the time Intervals self.timer = Timer.scheduledTimer(withTimeInterval: 0.7,repeats: false,block: { _ in if self.incrementer != self.textNeedDisplaying.count - 1 { self.internalTimer?.invalidate() self.animatingLabel.text = self.textNeedDisplaying[self.incrementer] self.incrementer += 1 } else { self.timer?.invalidate() self.internalTimer?.invalidate() self.mainTimer?.invalidate() self.animatingLabel.text = "DONE" } }) }) } }
如果你想让各个字母都有动画让我知道.我会做到这一点……确保标签的宽度约束足够大以适应你的话.此外,如果代码可以更简洁或更好,请告诉我.
2)使用Lottie和After Effects进行更加个性化的过渡.如果您对此感兴趣,请告诉我:链接:https://airbnb.design/lottie/.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。