[英]Animation stops after segueing to different view controller
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. 我的应用程序中有一个动画,它基本上只是使
UIButton
增长和缩小,使用户明白应该点击它。
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). 问题是,虽然它在视图首次出现时工作正常,但如果我转到另一个视图控制器(带有segue)然后返回(没有任何反应),它就不起作用。
Here is my code: 这是我的代码:
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()
}
Try Solution: 尝试解决方案
// Allows the animation to appear on View Controller
override func viewWillAppear(_ animated: Bool) {
super.viewDidAppear(true)
// Function call
expandAnimation()
}
// Allows the animation to disappear from View Controller
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(true)
// Function call
expandAnimation()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.