Skip to content

Instantly share code, notes, and snippets.

@Josscii
Last active March 31, 2017 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Josscii/51d5154583e38fef24a5380abdb18a0c to your computer and use it in GitHub Desktop.
Save Josscii/51d5154583e38fef24a5380abdb18a0c to your computer and use it in GitHub Desktop.
UIStatusBar 补充

补充

1,文章中提到在 View controller-based status bar appearance 为 YES 时,

2、在viewDidload中调用:[self setNeedsStatusBarAppearanceUpdate];

这一步经过测试是没有必要的,我在文档中找到这个 api 的注释:

This should be called whenever the return values for the view controller's status bar attributes have changed. If it is called from within an animation block, the changes will be animated along with the rest of the animation block.

也就是说当你改变了 status bar 的一些属性时,你需要调用这个方法来使它生效。

那么这个方法到底怎么用呢?

经过我打断点查看调用栈发现,这个方法会在 View Controller 出现时自动调用,然后调用 preferredStatusBarStyle 来得到最新的 style 的值。

所以我们可以用这个方法来动态的改变 status bar 的 style,比如用一个标志量来 flip,接着调用这个方法,然后在 preferredStatusBarStyle 中根据这个标志量返回不同的值即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment