Typing animation: deleting characters

后端 未结 2 1063
情书的邮戳
情书的邮戳 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:24

    Why not do the following:

    func deleteLetter() {
        if textFieldMain.text != "" {
            textFieldMain.text = str.substringToIndex(textFieldMain.text.endIndex.predecessor())
        } else {
           typingAnimationTimer?.invalidate()
        }
    }
    

    By the way, if you start your timer with "repeats: true" in fireDeletionTimer() you don't need to recreate it again and again in deleteLetter()

    Also, stringByReplacingOccurrencesOfString() clears every instance of that letter in your text, not just the last one.

提交回复
热议问题