2017-06-15 5 views
4

ランダムな文字がその位置でスクランブルされ、特定の文字で停止するアニメーションを作りたかったのです。 これはUIView.animateを使用して実現できますか? ここでは、以下のことについて大まかに考えています。本当にこのインスピレーションのようなスクランブル文字をSwiftの位置でアニメーション化する方法は?

something like this

+0

文字を無作為にスクランブルして長さを変えても、無作為に単語を構成できない場合は、このコードの答えを書いても大丈夫でしょうか?私はこの考えが本当に好きです。 –

+0

これら2つのリンクを確認して、そのようなものが必要かどうか教えてください。 https://github.com/franklinsch/iOSDrawTextAnimation https://github.com/chuganzy/ShuffleTextLabel –

+0

@AaronZhengありがとうございました。それは役に立ちます。 – Raj

答えて

1

。あなたのアプリでこれを置くには二つの方法がまだあります 1)ここで私はあなたのインスタンスに対して作成されたコードです:
輸入の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/

+0

ありがとう、それは助けて、私もロッテリーを試してみます。 – Raj

関連する問題