1.UIScrollView设置contentInset的top 且设置位置 必须在最前面放后面有问题 以后再说
2.头部就是在UIScrollView之上
3.在scrollView代理方法中判断offset
contentInset 必须在前面
- (BaseTableView *)mainView
{
if (!_mainView) {
BaseTableView *tableView = [[BaseTableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - kCustomTabBarHeight) style:UITableViewStylePlain];
tableView.contentInset = UIEdgeInsetsMake(kContentInsetTop, 0, 0, 0);
tableView.scrollIndicatorInsets = tableView.contentInset;
[self.view addSubview:tableView];
tableView.delegate = self;
tableView.dataSource = self;
tableView.tableFooterView = [UIView new];
[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
tableView.backgroundColor = kColorBGTinyBlue;
if (@available(iOS 11.0, *))
{
tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
tableView.estimatedRowHeight = 0;
tableView.estimatedSectionFooterHeight = 0;
tableView.estimatedSectionHeaderHeight = 0;
}
else
{
self.automaticallyAdjustsScrollViewInsets = NO;
}
tableView.rowHeight = HEIGHT - kCustomTabBarHeight;
tableView.showsVerticalScrollIndicator = NO;
_mainView = tableView;
}
return _mainView;
}
flexView
//头部可伸缩模块
@property(nonatomic,strong)UIImageView *flexView;
- (UIImageView *)flexView
{
if (!_flexView) {
UIImageView *iv = [[UIImageView alloc]init];
[self.view addSubview:iv];
iv.clipsToBounds = YES;
iv.frame = CGRectMake(0, 0, WIDTH, kContentInsetTop);
[iv sd_setImageWithURL:@"https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2141197356,630198876&fm=11&gp=0.jpg".wppURL];
_flexView = iv;
}
return _flexView;
}
1.为了能到指定位置 不然会有偏移
dispatch_async(dispatch_get_main_queue(), ^{
[self.mainView setContentOffset:CGPointMake(0, -kHeaderHeight)];
});
scrollView代理方法
CGFloat offset = scrollView.contentOffset.y + scrollView.contentInset.top;
//伸缩
if (offset <= 0) {
self.flexView.top = 0;
self.flexView.height = fabs(offset) + kContentInsetTop;
CGFloat percent = self.flexView.height / kContentInsetTop;
//宽度整体扩大
self.flexView.width = WIDTH * percent;
self.flexView.left = - (WIDTH * (percent - 1) * 0.5);
} else {
CGFloat flexShowHeight = kStatusBarHeight + 30*ADAPTER_WIDTH;
CGFloat flexCriticalPoint = kContentInsetTop - flexShowHeight;
CGFloat minOffset = MIN(offset, flexCriticalPoint);
self.flexView.top = -minOffset;
self.flexView.height = kContentInsetTop;
//宽度整体恢复
self.flexView.width = WIDTH;
self.flexView.left = 0;
}
状态栏
_statusBarStyle = (progress < 0.5) ?UIStatusBarStyleDefault:UIStatusBarStyleLightContent;
//主动更新状态栏
[self.navigationController setNeedsStatusBarAppearanceUpdate];
网友评论