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

标签 swift xcode animation uiviewanimation tabbar

我有以下代码:

    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 更改为您要设置动画的任何 View 。然后随意调整初始比例、持续时间和 Spring 阻尼以获得您想要的动画!

关于swift - 如何创建推特标签栏推送动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62880389/

相关文章:

ios - 保留 Textview 状态

ios - 2 个完全相同的 iOS 应用程序,除了数据库不同

jquery - 在页面加载时自动设置矩形宽度的动画(无需按下按钮)

jquery - Bootstrap Carousel 过渡元素 + animate.css

ios - 想要使用 Scenekit 更改节点的 y 值

SwiftUI 的anchorPreference 折叠其 View 的高度

swift - 需要快速检索用户坐标

php - 从 Swift 到 php 脚本的 Http post 请求

ios - 如何在没有 Storyboard的情况下制作滑出菜单?

Swift playground 结果位置错误