先看下效果图(正常状态\上滑状态\下拉状态)
思路:
1.最底下是横向滑动的ScrollView,
2.然后上面添加两个可以左右切换的tableView,
3.tableView头部预留一片空白作为填充, 真正的头部添加在控制器的View上,
4.监听tableView的滑动, 根据偏移量执行不同的操作
上滑状态:改变headerView的纵坐标, 根据头部的高度设置悬停的位置,
下拉状态:改变headerView高度,模仿ScrollView下拉效果, 注意headerView里面的子控件的约束.
5.每次滑动时需要根据当前页面tableView的偏移,去设置另一个页面tableView的偏移
6.headerView会拦截下面tableView的滑动事件, 所以滑动头部的时候没有效果, 我们需要添加一个pan手势, 模仿滑动事件
7.如果iOS 11上有问题, 可以加上这句(这个是修改全局的ScrollView,如果怕影响别的页面就只给backgroundScrollView设置即可)
if (@available(iOS 11.0, *)) {
[UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
具体实现如下:
#define kScorllPoint (kCompanyHeaderH - kNavigationHeight - 50.0)
@interface HDCompanyController ()<UIScrollViewDelegate>
@property (nonatomic, strong) CompanyHeaderView *headerView;
@property (nonatomic, strong) UIScrollView *backgroundScrollView; // 最底部横向ScrollView
@property (nonatomic, strong) UIView *navigationBar;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *backItme;
@property (nonatomic, strong) UIButton *backView;
@property (nonatomic, strong) HDHotJobController *jobVC;
@property (nonatomic, strong) HDCompanyBriefController *briefVC;
@end
@implementation HDCompanyController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self setUpSubviews];
}
- (void)setUpSubviews{
self.edgesForExtendedLayout