一、思维导图
二、当控制器一导航是隐藏的,控制器二导航是显示的,控制器一push控制器二,左滑手势返回时会出现黑框,
解决办法是:
1.在控制器一将要出现的方法设置为:[self.navigationController setNavigationBarHidden:YES animated:YES];
2.在控制器二将要出现的方法设置为:[self.navigationController setNavigationBarHidden:YES animated:YES];
三、刚开始导航是隐藏的,滚动一段距离后,显示导航。
解决思路是:
1.自定义一个和导航一样高的view,然后加到TableView的headView上。
2.当滑动的时候,通过偏移位置/滑动固定高度来设置view的alpha(透明度)。
3.当滑动到固定的高度后,view的alpha为1,那个view就会完全显示。
4.同时当没有滑动或没有滑动到固定的高度的时候,view不会显示或不能完全显示。
六.上代码。
#import "BSJMainNavViewController.h" @interface BSJMainNavViewController ()<UIGestureRecognizerDelegate> @end @implementation BSJMainNavViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UINavigationBar *navBar = [UINavigationBar appearance]; NSMutableDictionary *navInfo = [NSMutableDictionary dictionary]; navInfo[NSFontAttributeName] = [UIFont systemFontOfSize:16]; [navBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault]; [navBar setTitleTextAttributes:navInfo]; //当重写导航的push方法时,导航的手势就失效了,可以这样写 self.interactivePopGestureRecognizer.delegate = self; } - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{ if (self.childViewControllers.count >=1) { UIButton *leftButton = [[UIButton alloc] init]; [leftButton setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal]; [leftButton setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted]; [leftButton setTitle:@"返回" forState:UIControlStateNormal]; [leftButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [leftButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; [leftButton sizeToFit]; [leftButton addTarget:self action:@selector(backItemClick:) forControlEvents:UIControlEventTouchUpInside]; //按钮中有个imageView 和Label //设置这个是设置imageView的内边距,如果设置它会imageView向内缩进 // leftButton setImageEdgeInsets:<#(UIEdgeInsets)#> //设置这个是设置title的内边距,如果设置它会title向内缩进 // leftButton setTitleEdgeInsets:<#(UIEdgeInsets)#> //设置整个按钮的内边距 [leftButton setContentEdgeInsets:UIEdgeInsetsMake(0,-20, 0, 0)]; viewController.hidesBottomBarWhenPushed = YES; viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton]; } //最后再调这段代码,上面的代码是先改导航的左边按钮 [super pushViewController:viewController animated:animated]; } #pragma mark --- delegate - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ //因为如果不设置>1,在主页面这个手势也会起作用,这样的话就不能push了就有bug return self.childViewControllers.count > 1; } #pragma mark --- response methods - (void)backItemClick:(UIButton *)sender{ [self popViewControllerAnimated:YES]; } @end