ScrollView嵌套Collectionview无痕衔接四向滚动,支持自定义TitleView

示例:


示例.gif

github地址:https://github.com/CoderLineChan/LCPageView

实现:
最底层是一个MainScrollView。
然后MainScrollView的上部分是headView, 中间部分是TitleView, 下面部分是Collectionview。

红色为自定义头部headView, 标题为自定义TitleView, 最后下面是Collecrionview里面装的ViewController

主要运用runtime拦截了_notifyDidScroll方法, 不需要在ViewController向PageView传滚动代理

使用: (注意)只需要在ViewController里面把主要的滚动视图赋值给 lcScrollView 即可,

/// pageViewController
- (void)testPageView
{
    NSArray *titles = @[@"测试&测试1", @"测试&测试2", @"主页", @"我的"];
    NSMutableArray *array = [NSMutableArray array];
    for (NSString *title in titles) {
        TestViewController3 *vc = [[TestViewController3 alloc] init];
        vc.title = title;
        [array addObject:vc];
    }
    UIView *headView = [[UIView alloc] init];
    headView.backgroundColor = [UIColor redColor];
    headView.frame = CGRectMake(0, 0, kScreenW, 150);

    /// 基本样式(如果自定义titleView则不需要传)
    LCPageViewStyle *style = [[LCPageViewStyle alloc] init];    

    CGRect frame = CGRectMake(0, 64, kScreenW, kScreenH - 64);
    /// 自定义标题
    TestTitleView *titleView = [[TestTitleView alloc] initWithFrame:CGRectMake(0,0, kScreenW, 38) titles:titles pageViewStyle:style];
    [titleView initSuperTitleView];
    
    /// 主pageView
    self.pageView = [[LCPageView alloc] initWithFrame:frame headView:headView childControllers:array parentController:self customTitleView:titleView pageViewStyle:style];
    
    /// 是否开启整体bounces/刷新
    self.pageView.mainScrollView.bounces = self.isOverall;
    if (self.isOverall) {
        __weak typeof(self) weakSelf = self;
        self.pageView.mainScrollView.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
            NSLog(@"开启刷新");
            [weakSelf endRefresh];
        }];
    }
    [self.view addSubview:self.pageView];
}
/// TestViewController3 
- (void)viewDidLoad {
    [super viewDidLoad];
    self.lcScrollView = self.tableView;
}

默认样式会慢慢增加, 因为每个app的样式都是不一样的, 所以这里只会增加常见的几种样式, 需要更多样式,请继承LCTitleView 自己写各种样式, 为什么要继承呢? 因为只有继承了才会有左右滚动的代理方法。headView也会增加对应的上下滚动代理。
新增加两三种标题的样式!!!!!!!

本文参考:https://blog.csdn.net/glt_code/article/details/78576628

你可能感兴趣的:(ScrollView嵌套Collectionview无痕衔接四向滚动,支持自定义TitleView)