iOS中给自定义tabBar的按钮添加点击放大缩小的动画

  • 之前想过一些通过第三方的方式实现动画,感觉有点麻烦,就自己写了一个
  • 不足之处还望大家多多指出
// 一句话,写在UITabBarController.m脚本中,tabBar是自动执行的方法  
  
  
// 点击tabbarItem自动调用  
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item  
{  
    NSInteger index = [self.tabBar.items indexOfObject:item];  
  
    [self animationWithIndex:index];  
  
    if([item.title isEqualToString:@"发现"])  
    {  
      // 也可以判断标题,然后做自己想做的事<img alt="得意" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/proud.gif" />  
    }  
  
}  
- (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];  
   
}  
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,366评论 25 709
  • 得不到的永远在骚动,被偏爱的都有恃无恐。写词的人七分入骨,唱歌的三分入目。生活中我们不经排练,有序上场。 和最好的...
    陶得阅读 298评论 0 0
  • 1 今天从成都返回上海,在双流机场机场排队安检的时候,听到排在我后面的一位男士在与人微信语音聊天,因为他的语言比较...
    杨中兴阅读 411评论 0 0
  • 一首歌赞美一个城市、这在原创音乐里是很少见的。(成都)这首歌的词是赵雷辗转中国各个城市最终定曲于成都。这就说明,成...
    吴话舟阅读 394评论 0 1