如何在视图消失/重新出现后使UIViewAnimation连续

时间:2015-09-16 11:45:40

标签: ios swift uiview uiviewanimation

我在我的一个按钮上使用了shinyButton效果,我希望即使在视图消失后这个效果也是连续的,这意味着整个应用程序的运行时间。这是动画的逻辑:

 // Creates a glow effect in the button by setting its layer shadow properties
    func startGlowWithCGColor (growColor:CGColor) {
        self.layer.shadowColor = growColor
        self.layer.shadowRadius = 10.0
        self.layer.shadowOpacity = 1.0
        self.layer.shadowOffset = CGSizeZero
        self.layer.masksToBounds = false

        // Autoreverse, Repeat and allow user interaction.
        UIView.animateWithDuration(1.0, delay: 0, options: UIViewAnimationOptions.Autoreverse |                                                         UIViewAnimationOptions.CurveEaseInOut | UIViewAnimationOptions.Repeat
            | UIViewAnimationOptions.AllowUserInteraction,
            animations: { () -> Void in
                // Make it a 15% bigger
                self.transform = CGAffineTransformMakeScale(1.15, 1.15)
            }) { (Bool) -> Void in
                // Return to original size
                self.layer.shadowRadius = 0.0
                self.transform = CGAffineTransformMakeScale(1.0, 1.0)
        }
    }

    // Removes the animation
    func stopGlow () {
        self.layer.shadowRadius = 0.0
        self.transform = CGAffineTransformMakeScale(1.0, 1.0)
        self.layer.removeAllAnimations()
        self.layer.masksToBounds = true
    }

如何让它连续?

1 个答案:

答案 0 :(得分:0)

在viewWillAppear函数中调用startGlowWithCGColor函数:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    self.startGlowWithCGColor(growColor)
}

然后,这将触发动画按钮加载到视图重新出现,它将动画,直到你告诉它停止你的stop功能。