IOS开发——UIPageControl页面翻页循环
2014-03-11 20:59
246 查看
IOS开发——UIPageControl页面翻页循环
原理:比如桌面上从左到右,有一排10张图片,我们可以把第十张图片复制一份放到第1张图片之前,同时把第一张图片复制一份放置第10张图片之后。那么现在我们就有了12张图片,多添加的两张图片用作移形换位之用,让视觉上只能感受10张图片。
笔记之用,只有截取取一段代码:
原理:比如桌面上从左到右,有一排10张图片,我们可以把第十张图片复制一份放到第1张图片之前,同时把第一张图片复制一份放置第10张图片之后。那么现在我们就有了12张图片,多添加的两张图片用作移形换位之用,让视觉上只能感受10张图片。
笔记之用,只有截取取一段代码:
-(void)gmSectionZeroRowZero:(NSArray *)theImgArr andHight:(float)theHight{ //在传回的图片数组的对象个数基础上+2 self.ymSVCycle = [theImgArr count]+2; //为了实现循环,ScrollView 的宽度也要多两个单位 self.ymSoRoIV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, theHight)]; [self.ymSoRoIV setContentSize:CGSizeMake(320*self.ymSVCycle,theHight )]; //设置ScrollView 的初始偏移 [self.ymSoRoIV setContentOffset:CGPointMake(320, 0)]; [self.ymSoRoIV setBounces:NO]; [self.ymSoRoIV setPagingEnabled:YES]; [self.view addSubview:self.ymSoRoIV]; //设置代理 [self.ymSoRoIV setDelegate:self]; [self.ymCellView setFrame:CGRectMake(0, 0, 320, theHight)]; for(int i = 0;i < self.ymSVCycle ; i ++){ UIImageView *tempImg = [[UIImageView alloc]initWithFrame:CGRectMake(320*i, 0, 320, theHight)]; //索引为0时,赋最后一张图片 if(i == 0){ [tempImg setImage:[theImgArrobjectAtIndex:self.ymSVCycle-3]]; //索引为最后一个时,赋第一张图片 }else if(i == self.ymSVCycle-1){ [tempImg setImage:[theImgArr objectAtIndex:0]]; }else{ [tempImg setImage:[theImgArr objectAtIndex:i-1]]; } [self.ymSoRoIV addSubview:tempImg]; } //UIPageControl self.ymPVCFirst = [[UIPageControl alloc] init]; [self.ymPVCFirst setFrame:CGRectMake(350 - self.ymSVCycle*15, theHight-15, self.ymSVCycle*15,10)]; self.ymPVCFirst.numberOfPages = self.ymSVCycle-2;//总共多少页 self.ymPVCFirst.currentPage = 0;//默认选中第几页 [self.view addSubview:self.ymPVCFirst ]; [self.ymPVCFirst setDefersCurrentPageDisplay:YES]; // self.ymPVCFirst.userInteractionEnabled=NO; } //添加委托 [self.ymPVCFirst addTarget:selfaction:@selector(gmPVCFristAction)forControlEvents:UIControlEventTouchDown]; } #pragma mark UIScrollViewDelegate // 任何偏移改变 - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ CGPoint thePoint = [scrollView contentOffset]; if(thePoint.x / 320 == 0){ self.ymPVCFirst.currentPage = self.ymSVCycle - 2; } else if (thePoint.x / 320 == self.ymSVCycle - 1) { self.ymPVCFirst.currentPage = 0; }else{ self.ymPVCFirst.currentPage = thePoint.x / 320 - 1; } } - (void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView{ CGPoint thePoint = [scrollView contentOffset]; if(thePoint.x/320 == self.ymSVCycle-1){ scrollView.contentOffset = CGPointMake(320, 0); self.ymPVCFirst.currentPage = 0; }else if(thePoint.x/320 == 0){ scrollView.contentOffset =CGPointMake((self.ymSVCycle-2)*320, 0); self.ymPVCFirst.currentPage = self.ymSVCycle-2; } } //UIPageControl关联方法 -(void)gmPVCFristAction{ int page = self.ymPVCFirst.currentPage; [self.ymSoRoIVsetContentOffset:CGPointMake(320*page+320, 0)]; }
相关文章推荐
- iOS开发之 滚动视图 + 页面控件(UIScrollView + UIPageControl)
- iOS开发之修改分页控制器UIPageControl的图片和大小以及圆点之间的距离
- IOS开发UI基础UIPageControl的属性
- iOS开发-图片查看(ScrollView+UIPageControl)
- [IOS]通过UIPageControl+UIScrollView实现图片循环轮播
- IOS开发之UIScrollView与UIPageControl的用法
- ios开发学习-页面控制样式翻页、文字、颜色等效果源码分享
- IOS 滚动页面UIPageControl实例
- iOS开发 ----- UIScrollview UIPageControl
- iOS App开发中的UIPageControl分页控件使用小结
- iOS开发 -- UIpageControl
- iOS--UIScrollView和UIPageControl配合使用完成引用介绍页面
- 【IOS-DEMO】UIScrollView+UIPageControl 实现欢迎页面
- UIPageControl 分页控件-IOS开发
- iOS开发之定时滑动图片(UIPageControl,UIScrollView)
- 学习IOS开发UI篇--UI知识点总结(三) UIScrollView/UIPageControl/NSTimer
- iOS开发 底层抛析运行循环—— RunLoop
- iOS开发中ViewController的页面跳转和弹出模态
- IOS开发---OC语言-㉘内存管理ARC循环调用
- iOS 6编程-UIScrollView滚动视图和UIPageControl分页控件实现图像分页显示(2)