UINavigationController讲解(一)

UINavigationController讲解(一)

UINavigationController简单介绍

  1. 初始化

    //通过一个自定义的导航栏和工具栏创建导航控制器
    - (instancetype)initWithNavigationBarClass:(nullable Class)navigationBarClass toolbarClass:(nullable Class)toolbarClass NS_AVAILABLE_IOS(5_0);
    //使用系统默认的导航栏和工具栏,通过一个根视图创建导航控制器
    - (instancetype)initWithRootViewController:(UIViewController *)rootViewController;
    
  2. 导航栏常用方法

    //通过压栈方式压入新的控制器(切换界面)
    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; // Uses a horizontal slide transition. Has no effect if the view controller is already in the stack.
    //从栈中弹出顶部控制器(返回)
    - (UIViewController *)popViewControllerAnimated:(BOOL)animated; // Returns the popped controller.
    //从栈中弹出到某个控制器 返回所有pop的controller
    - (NSArray<__kindof UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated; // Pops view controllers until the one specified is on top. Returns the popped controllers.
    //直接pop到根视图控制器,弹出所有控制器
    - (NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated;
  3. 常用属性

    //栈顶的控制器
    @property(nullable, nonatomic,readonly,strong) UIViewController *topViewController; 
    //显示的controller(包括present出的控制器)
    @property(nullable, nonatomic,readonly,strong) UIViewController *visibleViewController;
    //栈中所有的控制器
    @property(nonatomic,copy) NSArray<__kindof UIViewController *> *viewControllers;
    //设置隐藏导航栏
    @property(nonatomic,getter=isNavigationBarHidden) BOOL navigationBarHidden;
    - (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated;
    //导航栏对象,只读属性
    @property(nonatomic,readonly) UINavigationBar *navigationBar;
    //隐藏状态栏
    @property(nonatomic,getter=isToolbarHidden) BOOL toolbarHidden NS_AVAILABLE_IOS(3_0);
    - (void)setToolbarHidden:(BOOL)hidden animated:(BOOL)animated;
    //状态栏对象
    @property(null_resettable,nonatomic,readonly) UIToolbar *toolbar;
    //导航中的返回手势对象
    //iOS7之后,在导航中右划会进行pop操作,设置这个的enable可以控制设置手势是否失效
    @property(nullable, nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer;
    //这个方法是为了iOS方法的命名统一,在导航中,其作用和push一样
    - (void)showViewController:(UIViewController *)vc sender:(nullable id)sender;
    //弹出键盘的时候隐藏导航栏
    @property (nonatomic, readwrite, assign) BOOL hidesBarsWhenKeyboardAppears;
    //屏幕滑动的时候隐藏导航栏,常用于tableView,上滑隐藏导航栏,下滑显示,带动画效果
    @property (nonatomic, readwrite, assign) BOOL hidesBarsOnSwipe;
    //滑动隐藏导航栏的手势
    @property (nonatomic, readonly, strong) UIPanGestureRecognizer *barHideOnSwipeGestureRecognizer;
    //横屏的时候隐藏导航栏
    @property (nonatomic, readwrite, assign) BOOL hidesBarsWhenVerticallyCompact;
    //敲击屏幕可以隐藏与显示导航栏
    @property (nonatomic, readwrite, assign) BOOL hidesBarsOnTap;
    //敲击屏幕的手势
    @property (nonatomic, readonly, assign) UITapGestureRecognizer *barHideOnTapGestureRecognizer;
  4. UINavigationDelegate

    //视图将要展示时调用的方法
    - (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);
    //这个方法设置导航控制器的首选设备方向
    - (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController NS_AVAILABLE_IOS(7_0);
    //下面两个方法可以对导航的转场动画进行设置
    - (nullable id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController;
    - (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC ;
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值