转到不同的视图控制器后动画停止 [英] Animation stops after segueing to different view controller

查看:22
本文介绍了转到不同的视图控制器后动画停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有一个动画,它基本上只是让 UIButton 增长和缩小,以便用户可以明显地点击.

I have an animation in my app that basically just makes a UIButton grow and shrink to make it obvious to the user that they should tap.

问题是,虽然它在视图第一次出现时工作正常,但如果我转到不同的视图控制器(带有 segue)然后返回(什么也没发生),它就不起作用了.

The problem is that while it works fine when the view first appears, it doesn't work if I go to a different view controller (with a segue) and then return (nothing happens).

这是我的代码:

override func viewWillAppear(animated: Bool) {
    expandAnimation()
}

func expandAnimation() {
    var animation = CABasicAnimation(keyPath: "transform.scale")
    animation.toValue = NSNumber(float: 0.9)
    animation.duration = 1
    animation.repeatCount = 100
    animation.autoreverses = true
    animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    appDevButton.layer.addAnimation(animation, forKey: nil)
}

我确定这是一个简单的修复,但我在网上找不到任何信息.

I'm sure it's a simple fix, but I couldn't find any info online.

推荐答案

当你离开视图时移除按钮的动画,

Remove the animation from the button when you leave the view,

    override func viewDidDisappear(animated: Bool) {
        super.viewDidDisappear(animated)
        appDevButton.layer.removeAllAnimations()
    }

这篇关于转到不同的视图控制器后动画停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆