iOS Swift tabbarItem点击时的动画效果

1.实现动画效果的方法

/// tabbarItem点击时的动画效果
    ///
    /// - Parameter index: 点击的item的位置
    func tabbarItemAnimationWithIndex(index: Int){
        var tabbarItem : [UIView] = []
        for tabBarButton in self.tabBar.subviews{
            if tabBarButton.isKind(of: NSClassFromString("UITabBarButton")!){
               tabbarItem.append(tabBarButton)
            }
        }
        let pulse = CABasicAnimation.init(keyPath: "transform.scale")
        pulse.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut)
        pulse.duration = 0.1
        pulse.repeatCount = 1
        pulse.fromValue = NSNumber.init(value: 0.8)
        pulse.toValue = NSNumber.init(value: 1.0)
        let itemView = tabbarItem[index]
        itemView.layer.add(pulse, forKey: "")
        self.indexFlag = index//声明的私有属性
    }

2.重写tabbarItem点击的方法

override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        let selectIndex = self.tabBar.items?.index(of: item)
        //声明的私有属性
        if self.indexFlag != selectIndex{
           self.tabbarItemAnimationWithIndex(index: selectIndex!)
        }
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容