美文网首页
TabBar 的Item添加动画

TabBar 的Item添加动画

作者: husky_duang | 来源:发表于2017-05-26 11:21 被阅读2294次

pragma mark - 给tabbar的Item添加动画

屏幕快照 2017-06-13 上午9.33.33.png

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    
    for (UIControl *tabBarButton in self.tabBar.subviews) {
        if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            [tabBarButton addTarget:self action:@selector(tabBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    KK_Log(@"只执行一次哦哦哦哦");
});

}
- (void)tabBarButtonClick:(UIControl *)tabBarButton
{
for (UIView *imageView in tabBarButton.subviews) {
    if ([imageView isKindOfClass:NSClassFromString(@"UITabBarSwappableImageView")]) {
        //需要实现的帧动画,这里根据需求自定义
        CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
        animation.keyPath = @"transform.scale";
        animation.values = @[@1.0,@1.3,@0.9,@1.15,@0.95,@1.05,@1.0];
        animation.duration = 1;
        animation.calculationMode = kCAAnimationCubic;
        //把动画添加上去就OK了
        [imageView.layer addAnimation:animation forKey:nil];
    }
}
}

相关文章

网友评论

      本文标题:TabBar 的Item添加动画

      本文链接:https://www.haomeiwen.com/subject/kogtfxtx.html