美文网首页
tabbarItem动画

tabbarItem动画

作者: Fisher123 | 来源:发表于2017-12-29 22:39 被阅读19次
//写在TabBarController .m文件中
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSInteger index = [self.tabBar.items indexOfObject:item];
if (self.indexFlag != index) {
[self animationWithIndex:index];
    }
}

// 执行动画
- (void)animationWithIndex:(NSInteger)index {
NSMutableArray * tabbarbuttonArray = [NSMutableArray array]; 
for (UIView *tabBarButton in self.tabBar.subviews){
if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
[tabbarbuttonArray addObject:tabBarButton]; }
}
CABasicAnimation*action = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
action.timingFunction= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
action.duration = 0.08;
action.repeatCount= 1;
action.autoreverses= YES;
action.fromValue= [NSNumber numberWithFloat:0.7]; 
action.toValue= [NSNumber numberWithFloat:1.2]; 
[[tabbarbuttonArray[index] layer]
addAnimation:action forKey:nil]; 
self.indexFlag = index;
}


相关文章

网友评论

      本文标题:tabbarItem动画

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