UINavigationController 相关属性,方法

初始化

通过一个自定义的导航栏和工具栏创建导航控制器
- (instancetype)initWithNavigationBarClass:(nullable Class)navigationBarClass toolbarClass:(nullable Class)toolbarClass NS_AVAILABLE_IOS(5_0);

 

使用系统默认的导航栏和工具栏,通过一个根视图创建导航控制器
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController;  

 

操作控制

压入新的视图控制器
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;


弹出一个视图控制器 返回的是pop的controller
- (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated;

  

弹出到某个视图控制器 返回所有pop的controller
- (nullable NSArray<__kindof UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;

 

直接pop到根视图控制器,返回所有被pop的controller
- (nullable NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated;

 

返回栈顶的controller
@property(nullable, nonatomic,readonly,strong) UIViewController *topViewController;
返回显示的controller
@property(nullable, nonatomic,readonly,strong) UIViewController *visibleViewController;

上面两个方法的区别在于,topViewController是返回被push出的最后一个controller,但是如果之后又有present进行莫泰跳转,visibleViewController会返回当前显示的controller。例如A-push-B-present-C,则topViewController会返回B,visibleViewController会返回C。


获取和设置管理的视图控制器
@property(nonatomic,copy) NSArray<__kindof UIViewController *> *viewControllers;

 

获取导航栏是否隐藏
@property(nonatomic,getter=isNavigationBarHidden) BOOL navigationBarHidden;

设置隐藏导航栏

- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated;

 

导航栏对象 bar全局唯一,只读属性
@property(nonatomic,readonly) UINavigationBar *navigationBar;

 

获取隐藏状态

@property(nonatomic,getter=isToolbarHidden) BOOL toolbarHidden NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED;

隐藏状态栏

- (void)setToolbarHidden:(BOOL)hidden animated:(BOOL)animated NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED;

状态栏对象

@property(null_resettable,nonatomic,readonly) UIToolbar *toolbar NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED;

 

下面说代理

@property(nullable, nonatomic, weak) id<UINavigationControllerDelegate> delegate;

 

导航中的返回手势对象  iOS7之后,在导航中右划会进行pop操作,设置这个的enable可以控制设置手势是否失效

@property(nullable, nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;

 

 

 

更好的用户体验 - ios8

//这个方法是为了iOS方法的命名统一,在导航中,其作用和push一样
- (void)showViewController:(UIViewController *)vc sender:(nullable id)sender NS_AVAILABLE_IOS(8_0); // Interpreted as pushViewController:animated:

 

//弹出键盘的时候隐藏导航栏
@property (nonatomic, readwrite, assign) BOOL hidesBarsWhenKeyboardAppears NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;

 

//屏幕滑动的时候隐航栏,常用于tableView,上滑隐藏导航栏,下滑显示,带动画效果
@property (nonatomic, readwrite, assign) BOOL hidesBarsOnSwipe NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;

 

//滑动隐藏导航栏的手势
@property (nonatomic, readonly, strong) UIPanGestureRecognizer *barHideOnSwipeGestureRecognizer NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;

 

//横屏的时候隐藏导航栏
@property (nonatomic, readwrite, assign) BOOL hidesBarsWhenVerticallyCompact NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;

 

//敲击屏幕可以隐藏与显示导航栏

@property (nonatomic, readwrite, assign) BOOL hidesBarsOnTap NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;

 

 //敲击屏幕的手势

@property (nonatomic, readonly, assign) UITapGestureRecognizer *barHideOnTapGestureRecognizer NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;

 

 代理相关

 

//视图将要展示时调用的方法
- (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 ;

 

其它分类相关

@interface UIViewController (UINavigationControllerItem)

当前controller对应的导航项
@property(nonatomic,readonly,strong) UINavigationItem *navigationItem;

push的时候隐藏底部栏,如push后隐藏tabbar
@property(nonatomic) BOOL hidesBottomBarWhenPushed __TVOS_PROHIBITED;

管理它的导航控制器
@property(nullable, nonatomic,readonly,strong) UINavigationController *navigationController;

@end

 

@interface UIViewController (UINavigationControllerContextualToolbarItems)
@property (nullable, nonatomic, strong) NSArray<__kindof UIBarButtonItem *> *toolbarItems NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED;
- (void)setToolbarItems:(nullable NSArray<UIBarButtonItem *> *)toolbarItems animated:(BOOL)animated NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED;
@end

 

posted @ 2016-03-24 10:05  人生路1/5  阅读(625)  评论(0编辑  收藏  举报