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. Linux 搭建Hadoop集群错误锦集

    一.Hadoop集群配置好后,执行start-dfs.sh后报错,一堆permission denied zf sbin $ ./start-dfs.sh Starting namenodes on ...

  2. 机器学习--集成学习(Ensemble Learning)

    一.集成学习法 在机器学习的有监督学习算法中,我们的目标是学习出一个稳定的且在各个方面表现都较好的模型,但实际情况往往不这么理想,有时我们只能得到多个有偏好的模型(弱监督模型,在某些方面表现的比较好) ...

  3. [转]Extending the User Interface in Outlook 2010

    本文转自:https://msdn.microsoft.com/en-us/library/office/ee692172%28v=office.14%29.aspx#OfficeOLExtendin ...

  4. 关于Mysql+EF6本地运行和发布没有问题,发布到服务器上出现问题的解决方案

    这个问题折磨了我差不多两天,网上各种方法也找了个遍,但是都没有解决我的问题,后面通过自己仔细分析问题和排查,终于把问题解决了,以下是我的解决问题的步骤,希望能帮到各位,不要再被这些问题坑了 1,项目实 ...

  5. mongodb int型id 自增

    mongo的c#客户端提供了接口IIdGenerator,有guid和objectid等几种实现,但没有int型id的实现 接口主要2个方法,一个IsEmpty返回bool,判断当前id值是否是空(估 ...

  6. ubuntu上安装redis

    1.Redis简要介绍 访问Redis官方网站 https://redis.io/ 上面介绍到 ,redis是开源,BSD许可,高级的key-value存储系统,可以用来存储字符串,哈希结构,链表,集 ...

  7. Maven - dependency那些事儿

    身边有几位刚使用Maven的同学表示——在一个叫"pom.xml"的文件里声明一个依赖就不用去手动添加jar了,感觉这东西和自己手动管理依赖没太大区别. 当然,并不是这样,在此记录 ...

  8. Ajax 学习(一)

    此篇为学习笔记 概述 Ajax(Asynchronous Javascrpt And Xml)是一种运用于浏览器的技术,它可以在浏览器与服务器之间使用异步通信机制进行数据通信,从而允许浏览器向服务器获 ...

  9. MySQL填坑系列--Linux平台下MySQL区分大小写问题

    大家好,我是软件大盗(道),下面开始我们的<MySQL填坑系列>. 笔者最近又在MySQL的边缘试探,然后,试探着,试探着就报错了. 书接上文,系统连接数据库时报错:找不到DB_TIMIN ...

  10. Android Studio开发笔记

    工欲善其事,必先利其器. 来分享下一些tips吧. android studio优化 我的习惯是从visual studio沿袭过来的,所以快捷键都是参照VS改过来的. 设置调优 不打开上次打开的工程 ...