1.首先实现代理方法
#pragma mark -- UITabBarControllerDelegate
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
UIImageView* slider = (UIImageView*)[self.tabBar viewWithTag:TAB_SLIDER_TAG];
NSUInteger selectedIndex = [self.viewControllers indexOfObjectIdenticalTo:viewController];
if (slider)
{
[self.tabBar bringSubviewToFront:slider];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
CGRect frame = slider.frame;
frame.origin.x = [self horizontalLocationFor:selectedIndex];
slider.frame = frame;
[UIView commitAnimations];
}
else
{
[self addTabBarSliderAtIndex:selectedIndex];
}
}
2.步骤1中又两个方法,