简体   繁体   English

segueing到不同的视图控制器后动画停止

[英]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.

相关问题 单击单元格并转到其他视图时应用程序崩溃 controller - app crashes when cell is clicked and segueing to a different view controller 导航后视图停止动画 - View stops animation after navigation 将视图控制器导入另一个控制器进行segueing是否安全? - Is it safe to import a view controller to another controller for segueing? 与另一个控制器隔离后在控制器中处理响应 - Handing a response in a controller after segueing to another controller 使用导航控制器在视图控制器之间进行隔离 - segueing between view controllers with navigation controller 从View Controller模态切换到另一个控制器后,在View Controller上添加模糊效果 - Adding a blur effect on a View Controller after segueing from it to another one modally UIButton在第一次加载时不响应触摸,但是在从另一个视图控制器回退后可以工作 - UIButton doesn't respond to touch on first load, but works after segueing back from another view controller 在Swift中从文本字段中选择使用表视图的视图控制器时出现错误 - Error when segueing to view controller with Table View from Textfield in Swift 在导航控制器中重新选择视图控制器时,整个屏幕为空白 - When segueing back to view controller in navigation controller, entire screen is blank 隔离前如何在Main View Controller中加载Ta​​ble View - How to load Table View in Main View Controller before segueing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM