【问题标题】:How to insert a Twitter bounce animation to tab bar如何将 Twitter 弹跳动画插入标签栏
【发布时间】:2020-10-03 08:29:04
【问题描述】:

我有以下代码:

import UIKit

class AnimatedTabBarController: UITabBarController {

    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
    }()

    override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        // find index if the selected tab bar item, then find the corresponding view and get its image, the view position is offset by 1 because the first item is the background (at least in this case)
        guard let idx = tabBar.items?.firstIndex(of: item), tabBar.subviews.count > idx + 1, let imageView = tabBar.subviews[idx + 1].subviews.first as? UIImageView else {
            return
        }

        imageView.layer.add(bounceAnimation, forKey: nil)
    }

}

我正在尝试在您单击图标时创建 twitter 弹跳动画,尽管此代码没有执行任何操作。有谁知道我做错了什么?

【问题讨论】:

    标签: swift xcode class uitabbarcontroller


    【解决方案1】:

    我忘记为标签栏控制器设置类

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-02
      • 2014-03-20
      • 1970-01-01
      • 2019-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多