您的位置:首页 > 移动开发 > IOS开发

CodingNet - Learning - 11

2016-07-14 20:51 302 查看
前面讲到FliterMenu遮罩层菜单的实现,现在我们试着点击上面列表的内容
会发现,很帅地换了一个显示,整个过程自然,简洁

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

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

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

// 点击TabBarItem并且传递到tableivew刷新

- (void)tabBarItemClicked{

[super tabBarItemClicked];

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

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

[listView tabBarItemClicked];

}

}

初始化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;
});

利用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];
};

是否可以滚动

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

将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];

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;
}
如果iCarousel用得好,的的确确是个强大的东西!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS CodingNet