无限循环轮播图实现

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

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值