Add click zoom in and zoom out animation effect to the button of custom tabBar in iOS
- 2021-07-10 20:58:14
- OfStack
I thought about realizing animation through the third party before, and I felt a little troublesome, so I wrote one myself
I hope everyone can point out the shortcomings
// 1 Sentences , Written in UITabBarController.m In the script ,tabBar Is an automated method
// Click tabbarItem Automatic call
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
NSInteger index = [self.tabBar.items indexOfObject:item];
[self animationWithIndex:index];
if([item.title isEqualToString:@" Discover "])
{
// You can also judge the title , Then do what you want to do <img alt=" Proud " 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];
}