如何在swift中动画制作tabbar徽章数量
我想通过制表符动画制作徽章数量,如Bouncing Animation。有没有人用本机UITabBarController实现它。我没有使用任何第三方类在我的项目中添加UITabBarController。如何在swift中动画制作tabbar徽章数量
我做一些这样的事情之前,我将与大家分享 首先,我创建了两个功能 第一个是代码:
func loopThrowViews(view:UIView){
for subview in (view.subviews){
let type = String(describing: type(of: subview))
print(type)
if type == "_UIBadgeView" {
print("this is BadgeView")
animateView(view: subview)
}
else {
loopThrowViews(view:subview)
}
}
}
这个函数取观点和循环抛出其所有子视图,直到它找到徽章查看那么它的调用动画的方法这一个
func animateView(view:UIView){
let shakeAnimation = CABasicAnimation(keyPath: "position")
shakeAnimation.duration = 0.05
shakeAnimation.repeatCount = 50
shakeAnimation.autoreverses = true
shakeAnimation.fromValue = NSValue(cgPoint: CGPoint(x:view.center.x - 10, y:view.center.y))
shakeAnimation.toValue = NSValue(cgPoint: CGPoint(x:view.center.x + 10, y:view.center.y))
view.layer.add(shakeAnimation, forKey: "position")
}
您可以将此方法与自己的动画更换代码
所有你需要的是在任何你想动画徽章
loopThrowViews(view: self.tabBarController!.tabBar)
结果会是这样
Worked Perfectly :) –
检查github项目我创建一个扩展只需将它放在您的项目上,并调用方法,如示例 –
是的我使用该类别文件实现徽章动画。 –
调用此方法像这样我不认为你可以动画设置计数的默认方法..你可能必须创建自己的自定义视图,然后添加动画 –
@RakshithNandish是正确的,你可能有手动完成。你打开使用'pods'吗? –
你可以,我想它的设计不应该让你漫长。试试看吧。让我知道这是怎么回事 –