您的位置:首页 > 其它

无限循环轮播图实现

2015-04-09 15:14 288 查看
1. 导入XLCycleScrollView
2. 设置代理
3.

//无限循环轮播图
// _bannerScroll = [[XLCycleScrollView alloc] initWithFrame:CGRectMake(0, 64, self.view.width, 200)];
// _bannerScroll.datasource = self;
// _bannerScroll.delegate = self;
// [self.view addSubview:_bannerScroll];
4. 实现代理 默认第一张为本地图片 其余为网络请求的图片

#pragma mark
- (NSInteger)numberOfPages
{
return _list.count+1;
}

- (UIView *)pageAtIndex:(NSInteger)index
{

//小圆点跟随轮播图而
_page.currentPage = index - 1;
if (index == 1) {
_animation = [CABasicAnimation animationWithKeyPath:@"position"];
_aView.top = 64;
[_aView.layer addAnimation:_animation forKey:@"cc"];
}else{
_animation = [CABasicAnimation animationWithKeyPath:@"position"];
[_aView.layer addAnimation:_animation forKey:@"cc"];
_aView.top = -_aView.height;
}
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
if (index == 0 || [src isEqualToString:@""]) {
imgView.image = [UIImage imageNamed:@"万佳-new轮播ios.jpg"];
}else{
[imgView sd_setImageWithURL:[NSURL URLWithString:[[_list objectAtIndex:index -1] objectForKey:@"src"]]];
imgView.contentMode = UIViewContentModeScaleAspectFill;
imgView.clipsToBounds = YES;
}
return imgView;
}
#pragma mark -XLCycleScrollViewDelegate
- (void)didClickPage:(XLCycleScrollView *)csView atIndex:(NSInteger)index
{
NSLog(@"点击轮播图1");
AdvertisementViewController *advertisementVC = [[AdvertisementViewController alloc] init];
self.tabBarView.hidden = YES;
if (index ==0) {
return;
}
advertisementVC.url = [[_list objectAtIndex:index - 1] objectForKey:@"href"];
NSLog(@"-----url=%@", advertisementVC.url);
[self.navigationController pushViewController:advertisementVC animated:YES];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: