GMCPagingScrollView

https://github.com/GalacticMegacorp/GMCPagingScrollView

GMCPagingScrollView is a UIView containing a horizontally scrolling paging UIScrollView that supports page preloading, page dequeueing, and infinite scrolling.

GMCPagingScrollView是一个UIView,包含了一个水平方向翻页滚动的UIScrollView,支持预加载,重用以及无线滚动.

demo中提供的源码:

#import "DemoViewController.h"
#import "GMCPagingScrollView.h" static NSString * const kPageIdentifier = @"Page"; @interface DemoViewController () <GMCPagingScrollViewDataSource, GMCPagingScrollViewDelegate> @property (nonatomic, strong) GMCPagingScrollView *pagingScrollView; @end @implementation DemoViewController - (void)viewDidLoad {
[super viewDidLoad]; self.pagingScrollView = [[GMCPagingScrollView alloc] initWithFrame:CGRectMake(, , , )];
self.pagingScrollView.center = self.view.center;
self.pagingScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.pagingScrollView.dataSource = self;
self.pagingScrollView.delegate = self;
self.pagingScrollView.infiniteScroll = YES;
self.pagingScrollView.interpageSpacing = ;
[self.view addSubview:self.pagingScrollView]; [self.pagingScrollView registerClass:[UIView class] forReuseIdentifier:kPageIdentifier]; [self.pagingScrollView reloadData];
} #pragma mark - GMCPagingScrollViewDataSource - (NSUInteger)numberOfPagesInPagingScrollView:(GMCPagingScrollView *)pagingScrollView {
return ;
} - (UIView *)pagingScrollView:(GMCPagingScrollView *)pagingScrollView pageForIndex:(NSUInteger)index {
UIView *page = [pagingScrollView dequeueReusablePageWithIdentifier:kPageIdentifier]; switch (index) {
case :
page.backgroundColor = [UIColor redColor];
break;
case :
page.backgroundColor = [UIColor greenColor];
break;
case :
page.backgroundColor = [UIColor blueColor];
break;
} return page;
} - (void)pagingScrollViewDidScroll:(GMCPagingScrollView *)pagingScrollView
{
NSLog(@"x = %f", pagingScrollView.scrollView.contentOffset.x);
} @end

效果:

修改一下并使用SDWebImage来测试:

#import "DemoViewController.h"
#import "GMCPagingScrollView.h"
#import "SDWebImage.h" static NSString * const kPageIdentifier = @"Page"; @interface DemoViewController () <GMCPagingScrollViewDataSource, GMCPagingScrollViewDelegate> @property (nonatomic, strong) GMCPagingScrollView *pagingScrollView;
@property (nonatomic, strong) NSArray *dataArray; @end @implementation DemoViewController - (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor]; _dataArray = \
@[@"http://img4.duitang.com/uploads/item/201307/29/20130729153409_YCfU2.thumb.200_0.jpeg",
@"http://cdn.duitang.com/uploads/item/201212/08/20121208141407_3YGMi.thumb.200_0.jpeg",
@"http://cdn.duitang.com/uploads/item/201308/26/20130826211332_WZ4is.thumb.200_0.jpeg",
@"http://img4.duitang.com/uploads/item/201301/21/20130121223918_aFk4h.thumb.200_0.jpeg",
@"http://img4.duitang.com/uploads/item/201309/15/20130915114846_nsy2A.thumb.200_0.jpeg",
@"http://cdn.duitang.com/uploads/item/201306/20/20130620142009_X3fv3.thumb.200_0.jpeg",
@"http://img4.duitang.com/uploads/item/201306/17/20130617202501_Z2ZNP.thumb.200_0.jpeg",
@"http://img4.duitang.com/uploads/item/201201/23/20120123181139_EvHrc.thumb.200_0.jpg",
@"http://img4.duitang.com/uploads/item/201108/24/20110824232929_T85Zt.thumb.200_0.jpg",
@"http://cdn.duitang.com/uploads/blog/201308/06/20130806213223_Q2Jfj.thumb.200_0.jpeg",
@"http://cdn.duitang.com/uploads/item/201311/10/20131110141543_UMV24.thumb.200_0.jpeg",
@"http://cdn.duitang.com/uploads/item/201307/18/20130718225516_RBMnr.thumb.200_0.jpeg",
@"http://img4.duitang.com/uploads/item/201202/05/20120205163116_x2F4E.thumb.200_0.jpg",
@"http://img4.duitang.com/uploads/item/201202/19/20120219150016_r48NA.thumb.200_0.jpg",]; self.pagingScrollView = [[GMCPagingScrollView alloc] initWithFrame:self.view.bounds];
self.pagingScrollView.dataSource = self;
self.pagingScrollView.delegate = self;
self.pagingScrollView.infiniteScroll = YES;
self.pagingScrollView.interpageSpacing = ;
[self.view addSubview:self.pagingScrollView]; [self.pagingScrollView registerClass:[UIImageView class]
forReuseIdentifier:kPageIdentifier]; [self.pagingScrollView reloadData];
} #pragma mark - GMCPagingScrollViewDataSource - (NSUInteger)numberOfPagesInPagingScrollView:(GMCPagingScrollView *)pagingScrollView {
return [_dataArray count];
} - (UIView *)pagingScrollView:(GMCPagingScrollView *)pagingScrollView pageForIndex:(NSUInteger)index {
UIImageView *page = [pagingScrollView dequeueReusablePageWithIdentifier:kPageIdentifier]; [page setImageWithURL:[NSURL URLWithString:_dataArray[index]]];
page.contentMode = UIViewContentModeScaleAspectFit;
page.layer.masksToBounds = YES; return page;
} - (void)pagingScrollViewDidScroll:(GMCPagingScrollView *)pagingScrollView
{
NSLog(@"x = %f", pagingScrollView.scrollView.contentOffset.x);
} @end

[翻译] GMCPagingScrollView的更多相关文章

  1. 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...

  2. 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...

  3. [翻译]开发文档:android Bitmap的高效使用

    内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...

  4. 【探索】机器指令翻译成 JavaScript

    前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...

  5. 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...

  6. 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...

  7. 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...

  8. 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?

    0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...

  9. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点

    在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...

随机推荐

  1. Word2vec 理解

    1.有DNN做的word2vec,取隐藏层到softmax层的权重为词向量,softmax层的叶子节点数为词汇表大小 2-3的最开始的词向量是随机初始化的 2.哈夫曼树:左边走 sigmoid(当前节 ...

  2. MySQL的各种join

    常用的是这5个join 首先join = inner join   这里有说明:点击打开链接 这里我就不用表来说明了,例子看这里 简单的说就是 inner join:不以谁为基准,只有符合关系的才会选 ...

  3. Nodejs学习笔记(二)—事件模块

    一.简介及资料  http://nodejs.org/api/events.html  http://www.infoq.com/cn/articles/tyq-nodejs-event events ...

  4. bet阶段验收互评

    小组名字和链接 优点 缺点,bug报告 最终名次 Gakki赛高[二十四点小游戏] 1.界面与上阶段相比更好了2.新增闯关设计,提升游戏性3.功能完善 1.下载方式不方便2.排行榜设计较为简陋 1 编 ...

  5. Android设计原则和设计模式

    1. 设计模式的六大基本原则 1.0 总结: 因为抽象灵活性好,适应性广,只要抽象的合理,可以基本保持软件架构的稳定.而软件中易变的细节,我们用从抽象派生的实现类来进行扩展,当软件需要发生变化时,我们 ...

  6. Linux内核源码目录

    linux和Android的Makefile和android.mk Uboot流程分析(未编辑完) Kernel的IIC驱动分析(未编辑完)

  7. [POI 2014]RAJ-Rally

    Description 题库链接 给定一个 \(N\) 个点 \(M\) 条边的有向无环图,每条边长度都是 \(1\).请找到一个点,使得删掉这个点后剩余的图中的最长路径最短. \(1\leq N\l ...

  8. vue基于d2-admin的RBAC权限管理解决方案

    前两篇关于vue权限路由文章的填坑,说了一堆理论,是时候操作一波了. vue权限路由实现方式总结 vue权限路由实现方式总结二 选择d2-admin是因为element-ui的相关开源项目里,d2-a ...

  9. Node.js构建可扩展的Web应用1

    <Practical Node.js:Building Real-World Scalable Web Apps>[美]Azat Mardan(电子工业出版社) 安装node.js和NPM ...

  10. MySQL免安装版下载与配置

    1.     下载Mysql 官方:http://www.mysql.com→downloads→选社区版本MySQL Community Edition(GPL)→点击Community(GPL)D ...