TableView/ScrollView嵌套问题(附demo)

本文详细探讨了在iOS开发中如何处理TableView与ScrollView的嵌套问题,通过实例代码演示了解决方案,帮助开发者解决滚动冲突和用户体验优化的问题。
摘要由CSDN通过智能技术生成
先看下效果图(正常状态\上滑状态\下拉状态)
        
思路:
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 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值