大佬教程收集整理的这篇文章主要介绍了ios – 如何在Swift的位置上制作扰乱字母的动画?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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/.
以上是大佬教程为你收集整理的ios – 如何在Swift的位置上制作扰乱字母的动画?全部内容,希望文章能够帮你解决ios – 如何在Swift的位置上制作扰乱字母的动画?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。