Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 4    Views: 984

NCbuzz
Code is Art
Profile
Posts: 575
Reg: Sep 11, 2013
Lillington, NC
11,100
03/18/15 07:00 PM (9 years ago)

Here is how to hide tab-bar with animation

Found this and it adds a little animation to your tabbed app. Subtle look. Hope you canalso use it :) http://stackoverflow.com/questions/20935228/how-to-hide-tab-bar-with-animation-in-ios Works Great! ==== Code as listed above ========================================== // a param to describe the state change, and an animated flag // optionally add a completion block which matches UIView animation - (void)setTabBarVisible:(BOOL)visible animated:(BOOL)animated { // bail if the current state matches the desired state if ([self tabBarIsVisible] == visible) return; // get a frame calculation ready CGRect frame = self.tabBarController.tabBar.frame; CGFloat height = frame.size.height; CGFloat offsetY = (visible)? -height : height; // zero duration means no animation CGFloat duration = (animated)? 0.5 : 0.0; // changed original duration from 0.3 to 0.5 (I was using flip screen transition) [UIView animateWithDuration:duration animations:^{ self.tabBarController.tabBar.frame = CGRectOffset(frame, 0, offsetY); }]; } // know the current state - (BOOL)tabBarIsVisible { return self.tabBarController.tabBar.frame.origin.y < CGRectGetMaxY(self.view.frame); // see change below... } // illustration of a call to toggle current state - (IBAction)pressedButton:(id)sender { [self setTabBarVisible:![self tabBarIsVisible] animated:YES]; } ==================================================================== I needed to make a change in the code tabBarIsVisible to better handle 568 tall screens (changed < to <=), (used [UIScreen mainScreen].bounds.size.height ): return self.tabBarController.tabBar.frame.origin.y <= [UIScreen mainScreen].bounds.size.height; Note: Everyone's app will be different. However when I implemented it for my case- I always was entering this sample screen from a screen where the tabbar was displayed, and animated down and off screen in viewWillAppear: [self setTabBarVisible: ![self tabBarVisible] animated:YES]; And back up on screen in viewDidDisappear: [self setTabBarVisible: YES animated:YES];
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/18/15 09:08 PM (9 years ago)
Into the snippets they go. Thanks Buzz! Cheers! -- Smug
 
QC
Aspiring developer
Profile
Posts: 50
Reg: Apr 20, 2013
Milwaukee, WI
6,650
like
03/19/15 11:34 AM (9 years ago)
Thanks!
 
QC
Aspiring developer
Profile
Posts: 50
Reg: Apr 20, 2013
Milwaukee, WI
6,650
like
03/19/15 11:35 AM (9 years ago)
do you have an android version?
 
NCbuzz
Code is Art
Profile
Posts: 575
Reg: Sep 11, 2013
Lillington, NC
11,100
like
03/20/15 09:53 AM (9 years ago)
Have not looked for Android.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.