如何在iOS7中切换状态栏和淡入淡出效果(如照片应用程序)? [英] How to toggle status bar with a fade effect in iOS7 (like Photos app)?

查看:101
本文介绍了如何在iOS7中切换状态栏和淡入淡出效果(如照片应用程序)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想切换状态栏的可见性,就像在照片应用中一样。

I want to toggle the visibility of the status bar on tap, just like it does in the Photos app.

在iOS 7之前,此代码运行良好:

Prior to iOS 7, this code worked well:

-(void)setStatusBarIsHidden:(BOOL)statusBarIsHidden {

    _statusBarIsHidden = statusBarIsHidden;

    if (statusBarIsHidden == YES) {

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


    }else{

        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

    }

}

但我可以让它在iOS 7中运行。我发现的所有答案都只提供了永久隐藏栏但不切换的建议。

But I can't get it to work in iOS 7. All the answers that I found only offer suggestions for permanently hiding the bar but not toggling.

然而,必须有办法因为照片是这样的。

Yet, there must be a way since Photos does it.

推荐答案

默认情况下,在iOS 7或更高版本上,为了隐藏特定视图控制器的状态栏,以下内容:

By default on iOS 7 or above, to hide the status bar for a specific view controller, do the following:


  1. 如果要隐藏状态栏的视图控制器以模态方式呈现,并且 modalPresentationStyle 不是 UIModalPresentationFullScreen ,手动设置 modalPresentationCapturesStatusBarAppearance YES (例如,在 -presentViewController:animated:completion -prepareForSegue:如果你正在使用故事板)

  2. 覆盖 -prefersStatusBarHidden 在提供的控制器和r中在提供的控制器上调用<$ li>
  3. 调用 setNeedsStatusBarAppearanceUpdate

  1. if the view controller you want to hide the status bar with is being presented modally and the modalPresentationStyle is not UIModalPresentationFullScreen, manually set modalPresentationCapturesStatusBarAppearance to YES on the presented controller before it is presented (e.g. in -presentViewController:animated:completion or -prepareForSegue: if you're using storyboards)
  2. override -prefersStatusBarHidden in the presented controller and return an appropriate value
  3. call setNeedsStatusBarAppearanceUpdate on the presented controller

如果你想为它的外观或消失设置动画,请在动画块中执行第三步:

If you want to animate it's appearance or disappearance, do step three within an animation block:

[UIView animateWithDuration:0.33 animations:^{
    [self setNeedsStatusBarAppearanceUpdate];
}];

您还可以通过返回适当的 UIStatusBarAnimation来设置动画样式来自显示控制器中 -preferredStatusBarUpdateAnimation 的值。

You can also set the style of animation by returning an appropriate UIStatusBarAnimation value from -preferredStatusBarUpdateAnimation in the presented controller.

这篇关于如何在iOS7中切换状态栏和淡入淡出效果(如照片应用程序)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆