Typing animation: deleting characters

后端 未结 2 1041
情书的邮戳
情书的邮戳 2021-01-28 05:57

Here\'s a typing animation that adds up characters from an Array to the text of a text field at a fixed time interval:

@IBOutlet weak var textFieldMain: UITextFi         


        
2条回答
  •  一个人的身影
    2021-01-28 06:18

    I would rewrite the deleteLetter() method into something like this:

    func deleteLetter() {
        myString = myString.substringToIndex(myString.endIndex.predecessor())
        textFieldMain.text = myString
    
        typingAnimationTimer?.invalidate()
        if myString.characters.count > 0 {
            typingAnimationTimer = NSTimer.scheduledTimerWithTimeInterval(0.05, target: self, selector: "deleteLetter", userInfo: nil, repeats: false)
        }
    }
    

    Edit: Looks like Zoltan already beat me to it.

提交回复
热议问题