美文网首页
Tabbar页面切换弹性动画

Tabbar页面切换弹性动画

作者: 微步毂纹生 | 来源:发表于2017-06-20 10:48 被阅读22次

    写在自己封装的TabBarViewController里即可

    
    @interface WTTabBarViewController ()
    @property (assign,nonatomic) NSInteger index;
    @end
    
    - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
        NSInteger selectIndex = [tabBar.items indexOfObject:item];
        if (selectIndex != _index)  // 是否重复点击 (需要重复点击直接注释)
            [self animationWithIndex:selectIndex];
    }
    
    - (void)animationWithIndex:(NSInteger) index {
        NSMutableArray *tabbarbuttonArray = [NSMutableArray array];
        for (UIView *tabBarButton in self.tabBar.subviews)
            if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")])
                [tabbarbuttonArray addObject:tabBarButton];
        CABasicAnimation *pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        pulse.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        pulse.duration = 0.2;   //time
        pulse.repeatCount = 1;  //重复次数
        pulse.autoreverses = YES;   //回到初始状态
        pulse.fromValue = [NSNumber numberWithFloat:0.7];   //初始伸缩倍数
        pulse.toValue = [NSNumber numberWithFloat:1.3];     //结束伸缩倍数
        [[tabbarbuttonArray[index] layer] addAnimation:pulse forKey:nil];
        
        _index = index;
        
    }
    
    
    
    gif5新文件-2.gif

    借鉴http://www.cnblogs.com/yajunLi/p/6288811.html 感谢分享

    相关文章

      网友评论

          本文标题:Tabbar页面切换弹性动画

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