日常大老师语录:
五年——看似遥遥无期,实则稍纵即逝的一段时间.
随着自身的成长,一年的时间会变得越来越短暂.
也许,现在的一年与明年的一年不会再是同样的长度,不仅仅是长度,价值也截然不同.
或许,连这样无所事事,仅仅只是抬头仰望蓝天的时光,今后也会变得无比奢侈.
所以,现在就暂且让我尽情仰望这片干燥而又美丽的寒空吧.
___by 大老师
UINavigationController类在工程里接触了很多,老大们自己封装了一层,用在页面跳转,自己看着文档和类学习了下记点东西,仍待大量补充。
文档里的图:
viewControllers:一个存储视图的数组,理解为栈合适些。页面的跳转常见方法之一,就是用UINavigationController的相关push和pop函数,操作的对象就是类里的viewControllers数组,根视图下数组只有根视图本身。类里对应的函数有:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; // Uses a horizontal slide transition. Has no effect if the view controller is already in the stack.
- (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated; // Returns the popped controller.
- (nullable NSArray<__kindof UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated; // Pops view controllers until the one specified is on top. Returns the popped controllers.
- (nullable NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated; // Pops until there's only a single view controller left on the stack. Returns the popped controllers.
@property(nullable, nonatomic,readonly,strong) UIViewController *topViewController; // The top view controller on the stack.
@property(nullable, nonatomic,readonly,strong) UIViewController *visibleViewController; // Return modal view controller if it exists. Otherwise the top view controller.
@property(nonatomic,copy) NSArray<__kindof UIViewController *> *viewControllers; // The current view controller stack.
- (void)setViewControllers:(NSArray<UIViewController *> *)viewControllers animated:(BOOL)animated NS_AVAILABLE_IOS(3_0); // If animated is YES, then simulate a push or pop depending on whether the new top view controller was previously in the stack.
push 和pop都是带动画效果的,默认push是从右滑入,pop是从左撤出,网上看过可以自定动画的,有待研究看看。
viewControllers返回的是当前界面的界面数组,rootViewController返回的就是只有自己的数组。
UINavigationBar:常称为导航栏,在UINavigationController类里的定义是:
@property(nonatomic,readonly) UINavigationBar *navigationBar; // The navigation bar managed by the controller. Pushing, popping or setting navigation items on a managed navigation bar is not supported.
因为是UINavigationController下的属性,控制管理由controller负责,所以在对它进行pushNavigationItem和popNavigationItemAnimated操作时会崩溃,蛋疼地试了下报错这样:'Cannot call pushNavigationItem:animated: directly on a UINavigationBar managed by a controller.'
取当前UINavigationController下的UINavigationBar下的(UINavigationItem*)items属性返回的数组,数量也会一直是1。
这里需要单独区分下VC下的self.navigationItem和self.navigationController.navigationItem,每个ViewController有对应的唯一的UINavigationItem对象,而UINavigationController继承自ViewController,所以也有对应的UINavigationItem对象,但是对当前VC的导航栏不起任何作用,即修改它不能对当前展示的导航栏起到效果。每个VC的UINavigationItem和VC的UINavigationController是独立的,只是展示在UINavigationController上。
这篇文章对二者有比较详细的介绍:http://www.jianshu.com/p/f797793d683f
个人理解是:UINavigationController类下的UINavigationBar只是一块负责展示的区域,我们可以通过修改它的translucent、tintColor、setBackgroundImage等属性方法来修改导航栏的展示效果,但是它只负责展示viewController对应的UINavigationItem,不可以通过它来修改对应的item,即展示的title,按钮等。
toolBar: ...
delegate:UINavigationViewController的代理有下面几个:
@protocol UINavigationControllerDelegate <NSObject>
@optional
// Called when the navigation controller shows a new top view controller via a push, pop or setting of the view controller stack.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
- (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
- (nullable id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController NS_AVAILABLE_IOS(7_0);
- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC NS_AVAILABLE_IOS(7_0);
@end
前两个代理方法分别是在UINavigationController展示view和navigationItem之前和之后调用,可以实现对应操作。
navigationControllerSupportedInterfaceOrientations和navigationControllerPreferredInterfaceOrientationForPresentation代理返回支持的方向和首选方向。
最后的两个代理实现动画,暂未细看。
诶下班跑路~