Wongzigii Wongzigii - 1 year ago 93
iOS Question

Improve tabBar animation when hidden

I've think about how to make the tabBar 's hidden animation more elegant and smoothly:

Here is how I implement:

So I just want to improve the animation, while the tabBar is suddenly, you know, disappear and hidden.

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
[self.tabBarController.tabBar setHidden:YES];

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
[self.tabBarController.tabBar setHidden:NO];

Any suggestion?

Answer Source

Try adding this method:

- (void)setTabBarHidden:(BOOL)tabBarHidden animated:(BOOL)animated
  if (tabBarHidden == _isTabBarHidden)

  CGFloat offset = tabBarHidden ? self.tabBarController.tabBar.frame.size.height : -self.tabBarController.tabBar.frame.size.height;

  [UIView animateWithDuration:animated ? 0.6 : 0.0
                     self.tabBarController.tabBar.center = CGPointMake(self.tabBarController.tabBar.center.x,
                                                                       self.tabBarController.tabBar.center.y + offset);

  _isTabBarHidden = tabBarHidden;

Then you can call it like [self setTabBarHidden:YES animated:YES] and [self setTabBarHidden:NO animated:YES] to hide and show your bar, this will move it in and out of the screen instead of just make it instantly dissapear.

Don't forget to add a new bool property isTabBarHidden and also you can play with the values of the animation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download