如何创建推特标签栏推送动画

How to create twitter tab bar push animation

我有以下代码:

    private var bounceAnimation: CAKeyframeAnimation = {
        let bounceAnimation = CAKeyframeAnimation(keyPath: "transform.scale")
        bounceAnimation.values = [1.0, 1.4, 0.9, 1.02, 1.0]
        bounceAnimation.duration = TimeInterval(0.3)
        bounceAnimation.calculationMode = CAAnimationCalculationMode.cubic
        return bounceAnimation
    }()

这会创建图标变大然后变小的动画。我正在尝试创建图标变小然后恢复正常的动画,就像它被推送类似于 twitter、Spotify 等一样。我假设它只是在反弹值周围发生变化,尽管我不确定我将如何做到这一点.

我会像这样使用正常的 UIView.animate 函数:

UIView.animate(withDuration: 0.05, delay: 0, options: .curveLinear, animations: {
    view.transform = CGAffineTransform(scaleX: 1.05, y: 1.05)
}, completion: nil)

UIView.animate(withDuration: 0.3, delay: 0.05, usingSpringWithDamping: 0.2, initialSpringVelocity: 7, options: .curveEaseOut, animations: {
    view.transform = .identity
}, completion: nil)

只需将 view 更改为您要设置动画的任何视图。然后弄乱初始比例、持续时间和 spring 阻尼以获得您想要的动画!