ios - How to animate tabbar badge count in swift -
i want animate badge count on tabbar bouncing animation . has implemented native uitabbarcontroller . not using third party class adding uitabbarcontroller in project.
i thing before share code first create 2 functions first 1 :
func loopthrowviews(view:uiview){ subview in (view.subviews){ let type = string(describing: type(of: subview)) print(type) if type == "_uibadgeview" { print("this badgeview") animateview(view: subview) } else { loopthrowviews(view:subview) } } }
this function take view , loop throw subviews until find badge view it's call animate method 1
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") }
you can replace code @ method own animation
all need call method when ever want animate badge
loopthrowviews(view: self.tabbarcontroller!.tabbar)
the result
full example here https://github.com/aliadam/animatetabbarbadgeview
Comments
Post a Comment