导航栏的隐藏处理

最近在做项目,一个课程列表,进入的时候导航栏隐藏,展开section后,滑动tableview导航栏渐变显示出来,看似没什么,只是点击cell进入新页面再返回就出现一些问题,比如。。。
1、进到有导航栏的页面
2、进入没有导航栏的页面
关键问题在于contentOffset
解决方案:

//UIScrollView 代理
-(void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{
   __weak typeof(self) weakSelf = self;
    [UIView animateWithDuration:0.5 animations:^{
        scrollView.contentInset = UIEdgeInsetsZero;
        weakSelf.tableView.contentOffset = CGPointMake(0, 0);
    }];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    _scrollviewFlag = scrollView;
    self.title = _scheduleModel.name;
    if (scrollView.contentOffset.y <= 200) {
        scrollView.contentInset = UIEdgeInsetsZero;
        self.navigationController.navigationBar.alpha = (scrollView.contentOffset.y) / 200;
    }else{
        scrollView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
        self.navigationController.navigationBar.subviews.firstObject.hidden = NO;
    }
}
//MARK: -  life cycle 生命周期
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.alpha = 0;
    if (_scrollviewFlag.contentOffset.y == 0) {
        self.navigationController.navigationBar.alpha = 0;
    }else{
        UIImage *colorImage = [UIImage imageWithColor:KGlobalColor];
        [self.navigationController.navigationBar setBackgroundImage:colorImage forBarMetrics:UIBarMetricsDefault];
        self.navigationController.navigationBar.alpha = (_scrollviewFlag.contentOffset.y) / 200;
        _scrollviewFlag.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
        _tableView.frame = CGRectMake(0, -64, SCREEN_W ,SCREEN_H);
    }
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationController.navigationBar.alpha = (_scrollviewFlag.contentOffset.y) / 200;
    _scrollviewFlag.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
}
-(void)viewWillDisappear:(BOOL)animated{
    _tableView.frame = CGRectMake(0, -64, SCREEN_W ,SCREEN_H);//推到后台再回来会异常,所以设置
    self.navigationController.navigationBar.alpha = 1;
}
21528184782_.pic.jpg
11528184781_.pic.jpg

你可能感兴趣的:(导航栏的隐藏处理)