0

I have a tab bar controller in my code and I want to make the transition with animation between the tab bar items. I found a way to do this with the controllers, but not with the items. I know I have to use UIView.animate, but I don't know how. Any ideas?

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

I have a tabBarController with some tabBar items,when I click the item,it‘s scale will larger and then back to default size,it just looks as an animation. With Objective-C you can use as follows :

//didSelectItem

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{

        NSInteger index = [self.tabBar.items indexOfObject:item];
        [self animationWithIndex:index];
    }



//animation 

- (void)animationWithIndex:(NSInteger) index {
    NSMutableArray *tabBarBtnArr = [NSMutableArray array];
    for (UIView *tabBarBtn in self.tabBar.subviews) {
        if ([tabBarBtn isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            [tabBarBtnArr addObject:tabBarBtn];
        }

    }
    UIButton *btn=tabBarBtnArr[index];
    [UIView animateWithDuration:0.2 animations:^{
        btn.transform=CGAffineTransformMakeScale(1.2, 1.2);

    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.2 animations:^{
            btn.transform=CGAffineTransformIdentity;

        }];
    }];

}