iphone - 同时隐藏状态栏和导航栏,就像在图片应用程序中一样

标签 iphone ios animation uinavigationbar statusbar

我有一个包含很多文本的 View ,所以我想允许用户在单击时隐藏 statusBar+navigationBar。我真的很喜欢 Pictures 应用程序中的隐藏样式,其中 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.
}

但这不会同时隐藏栏。它使它们滑落。它与上述方法的此版本具有相同的效果:

- (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];
}

最佳答案

隐藏 UIStatusBar 动画:

[[UIApplication sharedApplication] setStatusBarHidden: YES withAnimation: UIStatusBarAnimationSlide];

隐藏 UINavigationBar 动画:

[UINavigationBar beginAnimations:@"NavBarFade" context:nil];
self.navigationController.navigationBar.alpha = 1;
[self.navigationController setNavigationBarHidden:YES animated:NO]; //Animated must be NO!
[UINavigationBar setAnimationCurve:UIViewAnimationCurveEaseIn]; 
[UINavigationBar setAnimationDuration:1.5];
self.navigationController.navigationBar.alpha = 0;
[UINavigationBar commitAnimations];

关于iphone - 同时隐藏状态栏和导航栏,就像在图片应用程序中一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15215920/

相关文章:

android - 如何在Android中使文本淡入淡出?

jquery animate 函数起作用然后反转它的变化

html - 使三 Angular 形动画拉伸(stretch)而不是移动

iphone - Gamer Center 排行榜不显示分数,每个用户只能访问自己的分数

ios - 更新到 Xcode 13,尝试在 iOS 但不是 macOS 上运行 SwiftUI 应用程序时获得唯一的错误代码

ios - 如何在 Swift 5 中使用 Alamofire 解析 json

ios - 在 AVCaptureMovieFileOutput 之后使用 AVPlayer 播放视频

ios - 如何在 Objective C 中异步加载数据 UITableview 滚动和核心数据获取

iphone - 将 SDK 特定的框架添加到 Xcode

ios - 交互式 Pop Gesture 的安全区域底部布局问题