我有一个包含很多文本的视图,所以我想允许用户在单击时隐藏 statusBar+navigationBar。我真的很喜欢图片应用程序中的隐藏样式,其中 statusBar 和 navigationBar 隐藏在一起(不滑动,只是淡出),带有一些动画持续时间,所以我尝试做类似的事情。这是我在 touchesDidBegan 方法中所做的:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
[UIView setAnimationDuration:0.5];
[UIView beginAnimations:@"" context:nil];
[[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:UIStatusBarAnimationNone];
[self.navigationController setNavigationBarHidden:(!self.navigationController.navigationBarHidden) animated:NO];
[UIView commitAnimations];
self.navigationController.navigationBar.translucent = !self.navigationController.navigationBar.translucent; // this is needed to make bars appear on top of my view.
}
但这并不会同时隐藏条形图。它使它们滑落。它与上述方法的此版本具有相同的效果:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
// deleted UIView animation, changed animation type to "slide"
[[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:UIStatusBarAnimationSlide];
// enabled animation for navBar
[self.navigationController setNavigationBarHidden:(!self.navigationController.navigationBarHidden) animated:YES];
self.navigationController.navigationBar.translucent = !self.navigationController.navigationBar.translucent; // this is needed to make bars appear on top of my view.
}
如果我摆脱 UIView 动画并隐藏没有动画的栏,它们会同时隐藏和出现,但太快了。也许我走错了方向。如果有人可以帮助我解决这个问题,将不胜感激。
编辑:得到它的工作
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// don't forget to set navigationBar.translucent to YES
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
[UINavigationBar setAnimationDuration:3.0];
[UINavigationBar beginAnimations:@"" context:nil];
[[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:NO];
if ([UIApplication sharedApplication].isStatusBarHidden)
[self.navigationController.navigationBar setAlpha:0.0];
else [self.navigationController.navigationBar setAlpha:1.0];
[UINavigationBar commitAnimations];
}