Aza*_*aza 6 iphone animation statusbar uinavigationbar ios
我有一个包含大量文本的视图,所以我希望允许用户在单击时隐藏statusBar + navigationBar.我真的很喜欢图片应用程序中的隐藏风格,其中statusBar和navigationBar隐藏在一起(不滑动,只是淡出),有一些animationDuration,所以我尝试做类似的事情.这是我在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.
}
Run Code Online (Sandbox Code Playgroud)
但这并不能同时隐藏条形图.它让它们向下滑动.它与上述方法的版本具有相同的效果:
- (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.
}
Run Code Online (Sandbox Code Playgroud)
如果我摆脱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];
}
Run Code Online (Sandbox Code Playgroud)
检查https://github.com/kirbyt/KTPhotoBrowser的演示,您可以在其中找到如何隐藏和显示状态栏和导航栏。
大多数情况下,您需要使用 NSTimer 设置 4 或 5 秒后自动隐藏 隐藏状态栏或导航栏
您还可以使用“触摸开始”来标记此计时器以随机显示或隐藏。
希望它能帮助您完成任务。使用 Barack 点查看上述 Github 链接的示例演示。您可以轻松找到隐藏和显示状态栏或导航栏的功能。
| 归档时间: |
|
| 查看次数: |
3331 次 |
| 最近记录: |