基本上,我想重新创建在选定标签后在YouTube应用中发生的以下动画。
这是我自定义标签栏控制器类中的当前内容:
import UIKit
class AnimatedTabBarController: UITabBarController {
private var bounceAnimation: CAKeyframeAnimation = {
let bounceAnimation = CAKeyframeAnimation(keyPath: "transform.scale")
bounceAnimation.values = [1.0, 0.9, 1.00, 1.00, 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?.index(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)
}
}
上面的代码允许我的标签在被选中时向内弹跳,可以添加到班级中以添加圆圈,也可以使圆圈巧妙地消失。
答案 0 :(得分:0)
您可以使用几种方法。您可以使用第三方,也可以创建自定义。就我而言,我使用自定义。