无限循环的ScrollView,原理以及实现,自动循环!!!

本人~菜鸟一枚,这两天闲着无聊,就寻思自己写一下ScrollView自动无限循环,借鉴了不少别人写的,但发现还都不是很全面,自己整合一下,以备初学者们参观研习,废话不多说,直接上代。

首先是.h

@protocol ImageScrollViewDelegate <NSObject>

//@required //必须不必须看你自己了。

-(void)didSelectImageAtIndex:(NSInteger)index;//代理事件,需要把点击是哪个图片传出来。

@end

@interface ImageScrollView : UIView

@property(nonatomic, assign) id<ImageScrollViewDelegate> delegate;

-(ImageScrollView *)initWithFrame:(CGRect)frame ImageArray:(NSArray *)imgArr;//这个是初始化方法应该都可以看懂的!

@end

接下来是.m

#define  screen_width [UIScreen mainScreen].bounds.size.width   //自己定义的宏 ,屏幕宽度。

#define  scren_Height [UIScreen mainScreen].bounds.size.height  //屏幕高度。

@interface ImageScrollView ()<UIScrollViewDelegate>

{   //声明了几个需要的控件,这个不需要暴露在外面,所以写在.m里,别问我为什么不用属性,我就是看着好看,用着舒服。

    CGRect scrollFrame;

    NSTimer *_timer;//定时器,自动播放时候要用到。

    NSInteger totalPage; //总共的页数。

    NSInteger curPage;// 当前的page。

    UIScrollView *mainScrollView;

    UIPageControl *pageControl;

}


@property(nonatomic,strong) NSMutableArray *curImageArray;

@property(nonatomic, strong) NSArray *imgArray;

@end


@implementation ImageScrollView


-(ImageScrollView *)initWithFrame:(CGRect)frame ImageArray:(NSArray *)imgArr{

    self = [super initWithFrame:frame];

    if (self) {

        //创建scrollview

        scrollFrame = frame;

        totalPage = imgArr.count;

        curPage = 2;

        self.curImageArray = [[NSMutableArray alloc</

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值