ios 11 tableView穿透导航栏 同时让section悬浮在导航栏下面

在iOS 11项目中,导航栏需透明,tableView在导航栏下方:

//解决导航栏不遮挡View

        if (@available(iOS 11.0, *)) {

            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

        } else {

            self.automaticallyAdjustsScrollViewInsets = NO;

        }


在滑动tableView之后, 导航栏逐渐显示,同时section在导航栏下方;

如果不处理section的位置, section会在屏幕顶部停留并被导航栏挡住一部分;

//该方法是当scrollView滑动时触发,因为UITableView继承自UIScrollView因此在这里也可以调用

    CGFloat header = 245;//这个header其实是section1 的header到顶部的距离(一般为: tableHeaderView的高度)

    if (scrollView.contentOffset.y < (header - NAVHEIGHT_64) && scrollView.contentOffset.y >= 0) {

        //当视图滑动的距离小于header时

        scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

    }else if(scrollView.contentOffset.y >= (header - NAVHEIGHT_64))

    {

        //当视图滑动的距离大于header时,这里就可以设置section1的header的位置啦,设置的时候要考虑到导航栏的透明对滚动视图的影响

        scrollView.contentInset = UIEdgeInsetsMake(NAVHEIGHT_64, 0, 0, 0);

    }

完美解决!

猜你喜欢

转载自blog.csdn.net/idlehand/article/details/78523171