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. springweb flux 服务器推送事件

    以前做服务器推送一般用轮询,后端主动给客户端推送不是很好解决.有时候也可以采用websocket 现在看了springwebflux,用它自带的方法做服务器推送方便多了. 代码如下: import o ...

  2. springcloud-06-feign的使用

    在spring Cloud Netflix栈中,各个微服务都是以HTTP接口的形式暴露自身服务的,因此在调用远程服务时就必须使用HTTP客户端.我们可以使用JDK原生的URLConnection.Ap ...

  3. Linux-(ps,grep)

    grep命令 1.命令格式: grep [option] pattern file 2.命令功能: 用于过滤/搜索的特定字符.可使用正则表达式能多种命令配合使用,使用上十分灵活. Linux系统中gr ...

  4. MySQL查看所有视图的命令

    有时为了查看特定数据库中所建立的所有视图,可以使用这个命令: 因为,视图其实就是一张虚拟的表,所有也可以认为是一张表,所有是 show table, 而它由于普通的表有所不同,所以有 status   ...

  5. java NIO系列教程2

    7.FileChannel Java NIO中的FileChannel是一个连接到文件的通道.可以通过文件通道读写文件. FileChannel无法设置为非阻塞模式,它总是运行在阻塞模式下. 打开Fi ...

  6. 微信公众号H5支付

    微信支付说明1.统一下单接口 统一支付接口: url: https://api.mch.weixin.qq.com/pay/unifiedorder 目的:通过此接口来创建预支付订单,获取订单支付需要 ...

  7. RabbitMQ上手记录–part 2 - 安装RabbitMQ

    上一篇<<RabbitMQ 上手记录-part 1>>介绍了一些基础知识,整理了一些基础概念.接下来整理一些安装步骤和遇到的问题. 我在CentOS7和Ubuntu16.4上都 ...

  8. Golang 知识图谱

  9. tcpdump一个命令的剖析

    简单介绍:用简单的话来定义tcpdump,就是:dump the traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具. tcpdump可以将网络中传送的数据 ...

  10. [转]Dotfuscator 使用图解教程

    本文转自:https://www.cnblogs.com/xiezunxu/articles/7228741.html Dotfuscator:是.NET混淆器和压缩器,它可以帮助您防止您的应用程序被 ...