[翻译] GMCPagingScrollView
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的更多相关文章
- 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...
- 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...
- [翻译]开发文档:android Bitmap的高效使用
内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...
- 【探索】机器指令翻译成 JavaScript
前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...
- 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...
- 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...
- 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...
- 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?
0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点
在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...
随机推荐
- python开发环境安装配置
需要安装的软件: Python2.7.14和Python3.6.4 要在电脑上同时安装两个版本 开发工具:PyCharm 是一个jetbrains的python开发工具 idea系列之一 Pyt ...
- SpringCloud源码解读
http://blog.didispace.com/Spring-Cloud%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/
- C++中对象模型
C++面向对象语言一大难点是继承,但又是不得不掌握的.简单的继承是很容易理解的,但是当涉及到多继承,设计到虚函数的继承,特别是涉及到虚继承时,问题就会变得复杂.下面的内容来自参考资料中的三篇文章.C+ ...
- DES对 json 、http参数加密解密算法
网上众多大神们的众多方式实现加解密操作及保障数据安全性.今天无意中发现一篇以 DES加密解密算法.摘抄如下 工具类: import java.security.SecureRandom; import ...
- Firebird 获取用户表及字段
select rdb$relation_fields.rdb$relation_name table_name, rdb$relations.rdb$description table_des, rd ...
- Django HTML 转义
HTML转义 模板对上下文传递的字符串进行输出时,会对以下字符自动转义 小于号< 转换为< 大于号> 转换为> 单引号' 转换为' 双引号" 转换为 " 与 ...
- JS 自定义对象 属性
js自定义对象 一,概述 在Java语言中,我们可以定义自己的类,并根据这些类创建对象来使用,在Javascript中,我们也可以定义自己的类,例如定义User类.Hashtable类等等. 目前在J ...
- CF696C PLEASE
矩阵快速幂+扩展欧拉定理 对于一个矩阵\(A\),我们有\(A^n \equiv A^{n\% \phi(m)+\phi(m)}(\%m)\) 经过简单的列举或推导可得 设目前进行了\(x\)轮,\( ...
- js-权威指南学习笔记18
1.除mouseenter和mouseleave外的所有鼠标事件都能冒泡. 2.传递给鼠标事件处理程序的事件对象有clientX和clientY属性,它们制订了鼠标指针相对于包含窗口的坐标. 3.一个 ...
- 常用数据库validationQuery语句
validationQuery是用来验证数据库连接的查询语句,这个查询语句必须是至少返回一条数据的SELECT语句.每种数据库都有各自的验证语句,下表中收集了几种常见数据库的validationQue ...