如何在Swift中调整动画速度?

Jam*_* Yu 1 animation ios swift

我是编程的新手,所以请原谅任何缺乏清晰度.我正在尝试使用animateWithDuration方法使我的一个按钮具有"闪烁效果".目前,它作为"淡入淡出",按钮逐渐显示并每1秒消失(我将持续时间设置为1.0).我希望降低动画的速度(不是持续时间,而是速度),这样动画效果会突然发生.动画的间隔需要每1秒钟保持一次.这有可能实现吗?我一直在研究,似乎animateWithDuration不允许这种规范......我是否需要通过另一种方法来解决这个问题?我在下面包含我的代码.谢谢你的帮助!顺便说一句,这都是在UIKit的UIViewController下.

override func viewDidLoad() {
    super.viewDidLoad()

    self.tapButton.alpha = 0
}

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(true)

    UIView.animateWithDuration(1.0, delay: 0, options: .Repeat | .AllowUserInteraction | .Autoreverse, animations: { () -> Void in self.tapButton.alpha = 1.0
        }, completion: nil )
} 
Run Code Online (Sandbox Code Playgroud)

Hug*_*nso 7

尝试添加曲线相关选项:

 UIViewAnimationOptions.CurveEaseOut
 UIViewAnimationOptions.CurveEaseIn
 UIViewAnimationOptions.CurveEaseInOut
Run Code Online (Sandbox Code Playgroud)

作为Apple文档的一员:

EaseInOut Easy -in缓出曲线使动画缓慢开始,在其持续时间的中间加速,然后在完成之前再次减速.这是大多数动画的默认曲线.

EaseIn缓入曲线使动画开始缓慢,然后随着进展而加速.

EaseOut缓出曲线会使动画快速开始,然后在完成时减慢速度.

所以,它将如下所述结束:

UIView.animateWithDuration(1.0, delay: 0, options: .Repeat | .AllowUserInteraction | .Autoreverse | UIViewAnimationOptions.CurveEaseOut, animations: { [weak self] in
        self?.tapButton.alpha = 1.0
        }, completion: nil)
Run Code Online (Sandbox Code Playgroud)