Permalink
Browse files

Animated show/hide of tabBar working

  • Loading branch information...
1 parent 9a8eb14 commit 03da38d18cf0329f614287f8438fff2d675a59e9 @myell0w myell0w committed Apr 27, 2012
Showing with 32 additions and 32 deletions.
  1. +0 −3 NGTabBarController/NGTabBarController.h
  2. +32 −29 NGTabBarController/NGTabBarController.m
@@ -43,9 +43,6 @@
/** The designated initializer. */
- (id)initWithDelegate:(id<NGTabBarControllerDelegate>)delegate;
-/** Sets the view controllers of the tab bar controller. */
-- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated;
-
- (void)setTabBarHidden:(BOOL)tabBarHidden animated:(BOOL)animated;
@end
@@ -19,7 +19,7 @@ @interface NGTabBarController () {
unsigned int didSelectViewController:1;
} _delegateFlags;
- BOOL _moveAnimationActive;
+ BOOL _animationActive;
}
// re-defined as read/write
@@ -53,6 +53,7 @@ @implementation NGTabBarController
@synthesize delegate = _delegate;
@synthesize tabBar = _tabBar;
@synthesize tabBarPosition = _tabBarPosition;
+@synthesize tabBarHidden = _tabBarHidden;
@synthesize animation = _animation;
@synthesize animationDuration = _animationDuration;
@synthesize tabBarItems = _tabBarItems;
@@ -68,7 +69,7 @@ - (id)initWithDelegate:(id<NGTabBarControllerDelegate>)delegate {
_oldSelectedIndex = NSNotFound;
_animation = NGTabBarControllerAnimationNone;
_animationDuration = kNGDefaultAnimationDuration;
- _moveAnimationActive = NO;
+ _animationActive = NO;
_tabBarPosition = kNGTabBarPositionDefault;
// need to call setter here
@@ -150,7 +151,9 @@ - (void)viewDidDisappear:(BOOL)animated {
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
- [self layout];
+ if (!_animationActive) {
+ [self layout];
+ }
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
@@ -223,14 +226,6 @@ - (void)setSelectedViewController:(UIViewController *)selectedViewController {
self.selectedIndex = [self.viewControllers indexOfObject:selectedViewController];
}
-- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated {
- if (animated) {
- // TODO:
- } else {
- self.viewControllers = viewControllers;
- }
-}
-
- (void)setViewControllers:(NSArray *)viewControllers {
if (viewControllers != _viewControllers) {
if (self.containmentAPISupported) {
@@ -303,20 +298,30 @@ - (void)setTabBarItems:(NSArray *)tabBarItems {
}
- (BOOL)tabBarHidden {
- return self.tabBar.hidden;
+ return _tabBarHidden || self.tabBar.hidden;
}
- (void)setTabBarHidden:(BOOL)tabBarHidden {
[self setTabBarHidden:tabBarHidden animated:NO];
}
- (void)setTabBarHidden:(BOOL)tabBarHidden animated:(BOOL)animated {
- if (animated) {
- // TODO:
- } else {
- self.tabBar.hidden = YES;
- self.selectedViewController.view.frame = self.childViewControllerFrame;
- [self layout];
+ if (tabBarHidden != _tabBarHidden) {
+ _tabBarHidden = tabBarHidden;
+
+ if (animated) {
+ _animationActive = YES;
+ [UIView animateWithDuration:kNGDefaultAnimationDuration
+ animations:^{
+ self.selectedViewController.view.frame = self.childViewControllerFrame;
+ } completion:^(BOOL finished) {
+ _animationActive = NO;
+ [self layout];
+ }];
+ } else {
+ self.selectedViewController.view.frame = self.childViewControllerFrame;
+ [self layout];
+ }
}
}
@@ -354,7 +359,7 @@ - (void)updateUI {
}
newSelectedViewController.view.frame = frame;
- _moveAnimationActive = YES;
+ _animationActive = YES;
if (self.animation == NGTabBarControllerAnimationMoveAndScale) {
[UIView animateWithDuration:kNGScaleDuration
@@ -406,13 +411,13 @@ - (void)updateUI {
newSelectedViewController.view.transform = CGAffineTransformMakeScale(1.f, 1.f);
} completion:^(BOOL finished) {
newSelectedViewController.view.frame = self.childViewControllerFrame;
- _moveAnimationActive = NO;
+ _animationActive = NO;
// call the delegate that we changed selection
[self callDelegateDidSelectViewController:newSelectedViewController atIndex:self.selectedIndex];
}];
} else {
- _moveAnimationActive = NO;
+ _animationActive = NO;
// call the delegate that we changed selection
[self callDelegateDidSelectViewController:newSelectedViewController atIndex:self.selectedIndex];
}
@@ -449,10 +454,8 @@ - (void)updateUI {
- (void)layout {
CGRect childViewControllerFrame = self.childViewControllerFrame;
- if (!_moveAnimationActive) {
- for (UIViewController *viewController in self.viewControllers) {
- viewController.view.frame = childViewControllerFrame;
- }
+ for (UIViewController *viewController in self.viewControllers) {
+ viewController.view.frame = childViewControllerFrame;
}
[self setupTabBarForPosition:self.tabBarPosition];
@@ -463,6 +466,10 @@ - (CGRect)childViewControllerFrame {
UIEdgeInsets edgeInsets = UIEdgeInsetsZero;
CGFloat inset = [self widthOrHeightOfTabBarForPosition:self.tabBarPosition];
+ if (self.tabBarHidden) {
+ inset = 0.f;
+ }
+
switch (self.tabBarPosition) {
case NGTabBarPositionTop:
edgeInsets = UIEdgeInsetsMake(inset, 0.f, 0.f, 0.f);
@@ -581,10 +588,6 @@ - (void)handleItemPressed:(id)sender {
}
- (CGFloat)widthOrHeightOfTabBarForPosition:(NGTabBarPosition)position {
- if (self.tabBarHidden) {
- return 0.f;
- }
-
CGFloat dimension = kNGTabBarControllerDefaultWidth;
// first item is responsible for dimension of tabBar, all must be equal (will not be checked)

0 comments on commit 03da38d

Please sign in to comment.