Swift - Animation to Loop forever not working

时间:2017-04-06 16:53:44

标签: ios swift

Good afternoon,

I am trying to do an animation with what's written in the button. Like this animation: https://s3.amazonaws.com/uploads.hipchat.com/37040/1764070/6Iow7n7WiWf6Naz/autoReverse.gif . For example, if "Cancel" were written in the button, I would like to "Cancel" change its color from red and blue fading in and out forever.

I tried doing like this, but didn't work:

override func viewDidAppear(_ animated: Bool) {
    self.test()
}

func test(){
    UIView.animate(withDuration: 1, delay: 0, options: [UIViewAnimationOptions.autoreverse, UIViewAnimationOptions.repeat], animations: {
        self.logInButton.setTitleColor(.red, for: .normal)
    }, completion: nil)
}

I also tried with the other 'animate function' without any options, just loping with two recursion methods. However, although I put 5 seconds of duration, the animations run extremely fast.

Can anyone help me? Thank you very much.

0 个答案:

没有答案