您的位置:首页 > 其它

tabBarItem动画

2015-06-10 19:52 267 查看
1.有时,我们需要为tabBarItem设置一些动画。在网上查了半天,没有结果。自己写了一个简单的bounce效果的动画

代码如下:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{

NSInteger currentIndex = tabBarController.selectedIndex;
NSInteger index = 0;
UITabBar *tabBar = tabBarController.tabBar;

for (int i = 0; i < tabBar.subviews.count; i++) {

UIView *button = tabBar.subviews[i];
if ([button isKindOfClass:NSClassFromString(@"UITabBarButton")]) {

if (index != currentIndex) {
index++;
}
else{

CAKeyframeAnimation *animation = [[CAKeyframeAnimation alloc]init];

animation.keyPath = @"transform.scale";
animation.duration = 1.0;
animation.values = @[@(1.0) ,@(1.4), @(0.9), @(1.15), @(0.95), @(1.02), @(1.0)];

UIView *imageview = [button.subviews firstObject];
//view.backgroundColor = [UIColor greenColor];
[imageview.layer addAnimation: animation forKey:nil];

UIView *labelview = [button.subviews lastObject];
[labelview.layer addAnimation:animation forKey:nil];
break;

}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: