2011-11-07 104 views
0

我想隐藏不在UINavigationController(这是一个模态视图)内的UINavigationBar,当按下按钮时。隐藏没有导航控制器的导航栏

我该怎么做?我希望它是动画。

+0

为什么你不使用导航控制器?它只是让每件事情都变得如此简单。 – Legolas

回答

2

如果你希望它是动画只需将其alpha下降到0.0

[UIView beginAnimations:@"Hide bar animation" context:NULL]; 
[UIView setAnimationDuration:0.5]; 
navigationBar.alpha = 0.0; 
[UIView commitAnimations]; 

然后回到1.0取消隐藏它

[UIView beginAnimations:@"Show bar animation" context:NULL]; 
[UIView setAnimationDuration:0.5]; 
navigationBar.alpha = 1.0; 
[UIView commitAnimations]; 

虽然在iOS 4以上版本,使用鼓励块动画方法

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion 

你可以这样使用:

[UIView animateWithDuration:0.5 
      animations:^{ 
       navigationBar.alpha = 0.0; 
      } 
      completion:^(BOOL finished){ 
       /* some completion code */ 
      }];