tabbar小动画和拦截pop事件

tabBar炫酷小动画

在UITabBarController的系统方法中获取点击tabbar的index值
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    
    NSInteger index = [self.tabBar.items indexOfObject:item];
    // indexFlag 可以注释,用来防止按钮重复出现动画效果
    if (self.indexFlag != index) {
        [self animationWithIndex:index];
    }
   
}

实现animationWithIndex方法
- (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.08;
    //执行次数
    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];
    self.indexFlag = index;
    
}

//简单粗暴,粘过去就能用

拦截pop事件。。。。一会写

你可能感兴趣的:(tabbar小动画和拦截pop事件)