如何在iOS7中切换状态栏和淡入淡出效果(如照片应用程序)? [英] How to toggle status bar with a fade effect in iOS7 (like Photos app)?
问题描述
我想切换状态栏的可见性,就像在照片应用中一样。
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:
- 如果要隐藏状态栏的视图控制器以模态方式呈现,并且
modalPresentationStyle
不是UIModalPresentationFullScreen
,手动设置modalPresentationCapturesStatusBarAppearance
到YES 在呈现之前呈现的控制器上的code>(例如,在
-presentViewController:animated:completion
或-prepareForSegue:
如果你正在使用故事板) - 覆盖
-prefersStatusBarHidden
在提供的控制器和r中在提供的控制器上调用<$ li>
- 调用
setNeedsStatusBarAppearanceUpdate
- if the view controller you want to hide the status bar with is being presented modally and the
modalPresentationStyle
is notUIModalPresentationFullScreen
, manually setmodalPresentationCapturesStatusBarAppearance
toYES
on the presented controller before it is presented (e.g. in-presentViewController:animated:completion
or-prepareForSegue:
if you're using storyboards) - override
-prefersStatusBarHidden
in the presented controller and return an appropriate value - 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屋!