iOS--UINavigationController学习笔记二

来源:互联网 发布:淘宝卖家中心在哪 编辑:程序博客网 时间:2024/06/12 19:35
1.定制statusBar的新发现
      
       前面提到过,将View controller-based status bar appearance设为YES,通过设置UINavigationBar.barStyle来改变statusBar的状态。这样有一点不好的地方在于,通常在viewController里面改变这一属性的值是影响到全局的,一般在viewController消失之前会复原。但是,这几天在看果爹的api,发现ViewController里面有这么两个方法
- (nullableUIViewController*)childViewControllerForStatusBarStyleNS_AVAILABLE_IOS(7_0)__TVOS_PROHIBITED;
- (nullableUIViewController*)childViewControllerForStatusBarHiddenNS_AVAILABLE_IOS(7_0)__TVOS_PROHIBITED;
官方的解释是说:如果这两个方法返回的是nil,在setNeedsStatusBarAppearanceUpdate方法调用之后,会调用自己的prefferedStatusBarStyle 和prefferedStatusBarHidden 方法,如果返回的是自己的childViewController,就是调用childViewController的prefferedStatusBarStyle 和prefferedStatusBarHidden 方法。这样,可以想到,设计一个UINavigationController的子类,复写上面的两个方法,统一返回UINavigationController.topViewController,这样每个UINavigationController栈中viewController,可以直接在prefferedStatusBarStyle 和prefferedStatusBarHidden方法中进行控制了。而且是不需要进行复原控制的。
       这种方法前提:是将View controller-based status bar appearance设为YES。

2.UINavigationControllerDelegate学习一

       UINavigationController提供了一个delegate,作用是可以全局定制一些导航栏的相关设置(最常见的就是统一定制导航栏顶部的返回样式),以及UINavigationController在进行push和pop的动画控制,现在好多文章都解释为转场动画,就是下一个场景(scene)viewController的view替代当前场景的viewController的view的动画。
      该delegate里面先是定义了下面两个方法:从方法名可以理解是在viewController将要显示时进行的调用。
- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController*)viewController animated:(BOOL)animated;
- (void)navigationController:(UINavigationController*)navigationController didShowViewController:(UIViewController*)viewController animated:(BOOL)animated;
    那么,在UIViewController的显示生命周期中的哪个阶段进行调用的呢?通过Demo写代码,打Log得出的一个截图

可以得出willShowViewController是在willAppear之后,didShowViewController是在didAppear之后进行调用的 
0 0