Tabbar页面切换弹性动画

写在自己封装的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页面切换弹性动画)