How to animate the scrambling of letters in place in Swift?

I wanted to create an animation in which random letters are compressed in their place and stopped at a specific letter. Can this be done using UIView.animate? The following is an approximate idea of ​​working with.

something like that

+4
source share
1 answer

Really like this inspiration. There are still two ways in the application: 1) Here is the code I created for your instance:
import UIKit

class ViewController: UIViewController {
    let listOfRandomLetters = ["@", "%", "*", "^", "1", "2", "3", " ", " "]
    var textNeedDisplaying = ["String", "Other Person", "Sample", "String", "Other Person", "Sample", "String", "Other Person", "Sample", "String", "Other Person", "Sample", "String", "Other Person", "Sample", "String", "Other Person", "Sample", "String", "Other Person", "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, repeats: true, 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/.

+1

Source: https://habr.com/ru/post/1679314/


All Articles