代码之家  ›  专栏  ›  技术社区  ›  Dan.code

如何停止按条件设置按钮动画

  •  0
  • Dan.code  · 技术社区  · 9 年前

    我有一个函数,可以使某个按钮变为淡入淡出。我在中启动动画 viewDidLoad 我如何创建删除此动画的函数?

    这是我的密码:

    func animateText(){
    
        UIView.animate(withDuration: 0.5, animations: {
            self.EnterDet.alpha = 1
        }, completion:  {
            (Comnpleted : Bool) -> Void in
    
            UIView.animate(withDuration: 0.5, delay: 1.5, options: UIViewAnimationOptions.allowUserInteraction, animations: {
            self.EnterDet.alpha = 0.1
    
            }, completion: {
                (Completed : Bool) -> Void in
                self.animateText()
            })
        })
    }
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   vacawama    9 年前

    更改完成块以检查 completed 参数 完整的 true 动画完成时(即未取消时)。仅当 完整的 真的

    UIView.animate(withDuration: 0.5, animations: {
        self.EnterDet.alpha = 1
    }, completion:  {
    
    (completed : Bool) -> Void in
        if completed {
            UIView.animate(withDuration: 0.5, delay: 1.5, options: UIViewAnimationOptions.allowUserInteraction, animations: {
                self.EnterDet.alpha = 0.1
    
            }, completion: {
                (completed : Bool) -> Void in
                if completed {
                    self.animateText()
                } else {
                    self.EnterDet.alpha = 1
                }
            })
        }
    })
    

    self.EnterDet.layer.removeAllAnimations()