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閱讀 173,476評論 25 708
  • 得不到的永遠在騷動,被偏愛的都有恃無恐。寫詞的人七分入骨,唱歌的三分入目。生活中我們不經排練,有序上場。 和最好的...
    陶得閱讀 295評論 0 0
  • 1 今天從成都返回上海,在雙流機場機場排隊安檢的時候,聽到排在我后面的一位男士在與人微信語音聊天,因為他的語言比較...
    楊中興閱讀 408評論 0 0
  • 一首歌贊美一個城市、這在原創音樂里是很少見的。(成都)這首歌的詞是趙雷輾轉中國各個城市最終定曲于成都。這就說明,成...
    吳話舟閱讀 382評論 0 1