CodingNet - Learning - 14

前面讲到FliterMenu遮罩层菜单的实现,现在我们试着点击上面列表的内容

会发现,很帅地换了一个显示,整个过程自然,简洁

但是问题是,并没有出现任何的容器类(Navigationcontroller, TabBarController )的跳转操作,怎么实现的?

这个时候我们就介绍一款老少咸宜的三方框架,大名鼎鼎的:iCarousel

我们讲项目中用到iCarousel的地方都标注出来:


1.点击TabBarItem并且传递到tableivew刷新

- (void)tabBarItemClicked{

    [super tabBarItemClicked];

    if (_myCarousel.currentItemView && [_myCarousel.currentItemView isKindOfClass:[ProjectListView class]]) {

        ProjectListView *listView = (ProjectListView *)_myCarousel.currentItemView;

        [listView tabBarItemClicked];

    }

}


2.初始化icarousl,多注意初始化项

    //添加myCarousel
    _myCarousel = ({
        iCarousel *icarousel = [[iCarousel alloc] init];
        icarousel.dataSource = self;
        icarousel.delegate = self;
        icarousel.decelerationRate = 1.0;
        icarousel.scrollSpeed = 1.0;
        icarousel.type = iCarouselTypeLinear;
        icarousel.pagingEnabled = YES;
        icarousel.clipsToBounds = YES;
        icarousel.bounceDistance = 0.2;
        [self.view addSubview:icarousel];
        [icarousel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.right.bottom.equalTo(self.view);
//            make.top.equalTo(self.view).offset(kMySegmentControl_Height);
            make.edges.equalTo(self.view);
        }];
        icarousel;
    });


3.利用clickBlock 和 iCarousel 的 scrollToItemAtIndex “绑定"起来

    __weak typeof(_myCarousel) weakCarousel = _myCarousel;
    
    //初始化过滤目录
    _myFliterMenu = [[PopFliterMenu alloc] initWithFrame:CGRectMake(0, 64, kScreen_Width, kScreen_Height-64) items:nil];
//    _myFliterMenu = [[PopFliterMenu alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Height) items:nil];

    __weak typeof(self) weakSelf = self;
    _myFliterMenu.clickBlock = ^(NSInteger pageIndex){
        if (pageIndex==1000) {
            [weakSelf goToProjectSquareVC];
        }else
        {
            [weakSelf fliterBtnClose:TRUE];
            [weakCarousel scrollToItemAtIndex:pageIndex animated:NO];
            weakSelf.selectNum=pageIndex;
        }
    };
    
    _myFliterMenu.closeBlock=^(){
        [weakSelf closeFliter];
    };



4.是否可以滚动

- (void)setIcarouselScrollEnabled:(BOOL)icarouselScrollEnabled{
    _myCarousel.scrollEnabled = icarouselScrollEnabled;
}



5.将XTSegmentControl 和 iCarousel绑定起来

//    __weak typeof(_myCarousel) weakCarousel = _myCarousel;

//    添加滑块
//    _mySegmentControl = [[XTSegmentControl alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kMySegmentControl_Height) Items:_segmentItems selectedBlock:^(NSInteger index) {
//        if (index == _oldSelectedIndex) {
//            return;
//        }
//        [weakCarousel scrollToItemAtIndex:index animated:NO];
//    }];
//    [self.view addSubview:_mySegmentControl];



6.iCarousel代理方法:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{
    Projects *curPros = [_myProjectsDict objectForKey:[NSNumber numberWithUnsignedInteger:index]];
    if (!curPros) {
        curPros = [self projectsWithIndex:index];
        [_myProjectsDict setObject:curPros forKey:[NSNumber numberWithUnsignedInteger:index]];
    }
    ProjectListView *listView = (ProjectListView *)view;
    if (listView) {
        [listView setProjects:curPros];
    }else{
        __weak Project_RootViewController *weakSelf = self;
        listView = [[ProjectListView alloc] initWithFrame:carousel.bounds projects:curPros block:^(Project *project) {
            [weakSelf goToProject:project];

            DebugLog(@"\n=====%@", project.name);
        } tabBarHeight:CGRectGetHeight(self.rdv_tabBarController.tabBar.frame)];
        
        listView.clickButtonBlock=^(EaseBlankPageType curType) {
            switch (curType) {
                case EaseBlankPageTypeProject_ALL:
                case EaseBlankPageTypeProject_CREATE:
                case EaseBlankPageTypeProject_JOIN:
                    [weakSelf goToNewProjectVC];
                    break;
                case EaseBlankPageTypeProject_WATCHED:
                case EaseBlankPageTypeProject_STARED:
                    [weakSelf goToProjectSquareVC];
                    break;
                default:
                    break;
            }
        };

        //使用新系列Cell样式
        listView.useNewStyle=_useNewStyle;

    }
    [listView setSubScrollsToTop:(index == carousel.currentItemIndex)];
    return listView;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值