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

enter image description here

full example here https://github.com/aliadam/animatetabbarbadgeview


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -