2017-07-25 56 views
0

我想通過製表符動畫製作徽章數量,如Bouncing Animation。有沒有人用本機UITabBarController實現它。我沒有使用任何第三方類在我的項目中添加UITabBarController。如何在swift中動畫製作tabbar徽章數量

+1

調用此方法像這樣我不認爲你可以動畫設置計數的默認方法..你可能必須創建自己的自定義視圖,然後添加動畫 –

+1

@RakshithNandish是正確的,你可能有手動完成。你打開使用'pods'嗎? –

+0

你可以,我想它的設計不應該讓你漫長。試試看吧。讓我知道這是怎麼回事 –

回答

2

我做一些這樣的事情之前,我將與大家分享 首先,我創建了兩個功能 第一個是代碼:

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) 

結果會是這樣

enter image description here

這裏充分例如https://github.com/AliAdam/AnimateTabbarBadgeView

+0

Worked Perfectly :) –

+0

檢查github項目我創建一個擴展只需將它放在您的項目上,並調用方法,如示例 –

+0

是的我使用該類別文件實現徽章動畫。 –