@interface UINavigationController : UIViewController
初始化
- (instancetype)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass NS_AVAILABLE_IOS(5_0);
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController;
//自定义?
// UINavigationController *nav = [[UINavigationController alloc]initWithNavigationBarClass:[UINavigationController class] toolbarClass:[UIToolbar class]];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController *view = [ViewController new];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:view];
self.window.rootViewController = nav;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
push pop
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (UIViewController *)popViewControllerAnimated:(BOOL)animated;
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;
oneViewController *one = [oneViewController new];
[self.navigationController pushViewController:one animated:YES];
[self.navigationController popViewControllerAnimated:YES];
ViewController *view = [ViewController new];
[self.navigationController popToViewController:view animated:YES];
[self.navigationController popToViewController:view animated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
@property(nonatomic,readonly,retain) UIViewController *topViewController; 顶部vc
@property(nonatomic,readonly,retain) UIViewController *visibleViewController; 可见vc
所有push的vc,也可以直接push过去(跨越多个vc)
@property(nonatomic,copy) NSArray *viewControllers; // The current view controller stack.
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated NS_AVAILABLE_IOS(3_0);
oneViewController *one = [oneViewController new];
twoViewController *two = [twoViewController new];
NSArray *arr = self.navigationController.viewControllers;
NSLog(@"%@",arr);
[self.navigationController setViewControllers:@[self,one,two]];
NavigationBar push pop 时是否隐藏,以及 bar :具体看 NavigationBar
@property(nonatomic,getter=isNavigationBarHidden) BOOL navigationBarHidden;
- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated;
@property(nonatomic,readonly) UINavigationBar *navigationBar;
oneViewController *one = [oneViewController new];
[self.navigationController setNavigationBarHidden:YES];或者:
self.navigationController.navigationBarHidden = YES;
[self.navigationController pushViewController:one animated:YES];
Toolbar push pop 时是否隐藏,以及 bar :具体看 NavigationBar 同上
@property(nonatomic,getter=isToolbarHidden) BOOL toolbarHidden NS_AVAILABLE_IOS(3_0);
- (void)setToolbarHidden:(BOOL)hidden animated:(BOOL)animated NS_AVAILABLE_IOS(3_0);
@property(nonatomic,readonly) UIToolbar *toolbar NS_AVAILABLE_IOS(3_0);
oneViewController *one = [oneViewController new];
[self.navigationController setToolbarHidden:YES];
self.navigationController.toolbarHidden = YES;
[self.navigationController pushViewController:one animated:YES];
@property(nonatomic, assign) id<UINavigationControllerDelegate> delegate; nav 的代理,具体看代理方法
左侧向右滑动,代替pop,(也可以自己设置方法,但是注意需要手势代理)
@property(nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer NS_AVAILABLE_IOS(7_0);
// self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
[self.navigationController.interactivePopGestureRecognizer addTarget:self action:@selector(newPop)];
-(void)newPop{
NSLog(@"pop");
}
@end