一开始几页滑动是没有问题的,等滑到三四个页面之后,就出现奇怪的缝隙,一开始死活找不到原因,最后在layout的代理方法minimumLineSpacingForSectionAtIndex返回值设置为0才解决,一开始想我只显示一行,跟这个应该没什么关系吧,就没设置,其他的两个代理方法minimumInteritemSpacingForSectionAtIndex和insetForSectionAtIndex都返回的是0.最后没辙了,1个晚上过去了,加了一个代理方法,然后问题就奇妙的解决了。

//添加UICollectionView

{

MyBigPictureFlowLayout *layout = [[MyBigPictureFlowLayout alloc] init];

//UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];

[layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];

self.albumCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64, kAllWidth, kAllHeight - 64) collectionViewLayout:layout];

self.albumCollection.backgroundColor = [UIColor clearColor];

self.albumCollection.dataSource = self;

self.albumCollection.delegate = self;

self.albumCollection.pagingEnabled = YES;

self.albumCollection.bounces = YES;

self.albumCollection.showsVerticalScrollIndicator = NO;

self.albumCollection.showsHorizontalScrollIndicator = NO;

self.albumCollection.contentSize = CGSizeMake(kAllWidth*self.dataSource.count, kAllHeight-64);

self.albumCollection.contentOffset = CGPointMake(kAllWidth*(self.index-1), 0);

[vContainer addSubview:self.albumCollection];

//注册cell的视图

static NSString *identifer = @"BigPictureCell";

[self.albumCollection registerClass:[BigPictureCell class] forCellWithReuseIdentifier:identifer];

}

#pragma mark-Delegate的代理方法

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{

return 0;

}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{

return 0;

}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

return CGSizeMake(kAllWidth, kAllHeight - 64);

}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{

return UIEdgeInsetsMake(0, 0, 0, 0);

}

UICollectionViewFlowLayout的写法:

#import <UIKit/UIKit.h>

@interface MyBigPictureFlowLayout : UICollectionViewFlowLayout

@end

#import "MyBigPictureFlowLayout.h"

@implementation MyBigPictureFlowLayout

-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{

NSArray *answer=[[super layoutAttributesForElementsInRect:rect] mutableCopy];

for (int i=1; i<[answer count]; i++) {

UICollectionViewLayoutAttributes *currentLayoutAttributes=answer[i];

UICollectionViewLayoutAttributes *prevLayoutAttributesans=answer[i-1];

NSInteger maximumSpacing=0;

//NSInteger origin=CGRectGetMaxX(prevLayoutAttributesans.frame);

float origin = prevLayoutAttributesans.frame.origin.x + prevLayoutAttributesans.frame.size.width;

CGRect frame=currentLayoutAttributes.frame;

frame.origin.x=origin+maximumSpacing;

currentLayoutAttributes.frame=frame;

}

NSLog(@"%@",answer);

return answer;

}

@end

代码地址:http://git.oschina.net/hyp.cn/demo

使用CollectionView做横向滑动分页效果:的更多相关文章

  1. 实现移动端touch事件的横向滑动列表效果

    要实现手机端横向滑动效果并不难,了解实现的原理及业务逻辑就很容易实现.原理:touchstart(手指按下瞬间获取相对于页面的位置)——>touchmove(手指移动多少,元素相应移动多少). ...

  2. 微信小程序 scroll-view 左右横向滑动没有效果(无法滑动)问题

    小程序组件 scroll-view 中分别有上下竖向滑动和左右横向滑动之分,在这次项目中刚好需要用到横向滑动,但在测试过程中发现横向滑动没有了效果(静止在那里没移动过),经调试发现: 1.scroll ...

  3. React Native学习(七)—— FlatList实现横向滑动列表效果

    本文基于React Native 0.52 Demo上传到Git了,有需要可以看看,写了新内容会上传的.Git地址 https://github.com/gingerJY/React-Native-D ...

  4. LinearLayout遇到的问题——利用LinearLayout做横向滑动冲突

    问题:当我添加两个TextView的时候,然后滑动,发现只生成了一个TextView. 就是 <?xml version="1.0" encoding="utf-8 ...

  5. 小程序 scroll-view 左右横向滑动没有效果(无法滑动)问题

    scroll-view 中的需要滑动的元素不可以用 float 浮动:

  6. 关于小程序 scroll-view 左右横向滑动没有效果(无法滑动)问题

    https://www.cnblogs.com/miu-key/p/7606024.html

  7. 【转】Android 实现ListView的滑动删除效果

    http://www.cnblogs.com/weixiao870428/p/3524055.html http://download.csdn.net/download/love_javc_you/ ...

  8. 《JavaScript 实战》:JavaScript 图片滑动切换效果

    看到alibaba的一个图片切换效果,感觉不错,想拿来用用.但代码一大堆的,看着昏,还是自己来吧.由于有了做图片滑动展示效果的经验,做这个就容易得多了. 效果预览 仿淘宝/alibaba图片切换: 默 ...

  9. 使用Jquery做分页效果

    之前写过一个PHP 的分页效果,但是今天小伙伴和我说了一个不适用后台单纯用前段的JS来写分页,整理了一下,代码如下: html: <div id="containet"> ...

随机推荐

  1. ecshop运行超过30秒超时的限制解决办法

    ecshop运行超过30秒超时的限制解决办法 ECSHOP模板/ecshop开发中心(www.68ecshop.com) / 2014-06-04 ecshop运行超过服务器默认的设置30秒的限制时会 ...

  2. vFloppy1.5-虚拟启动软盘

    vFloppy1.5为纯绿色免费软件,安装后不需要引导盘即可进入DOS,支持图形化访问NFTS系统格式,还可添加由光盘启动菜单选项,对于没有光驱,软驱的朋友非常实用. 到BIOS设置由光盘启动,或者打 ...

  3. Apache Kafka源码分析 - PartitionStateMachine

    startup 在onControllerFailover中被调用, initializePartitionState private def initializePartitionState() { ...

  4. delphi 最全日期格式_DateUtils时间单元说明

    DateUtils时间单元说明 CompareDate 函数 比较两个日期时间值日期部分的大小 CompareDateTime 函数 比较两个日期时间值的大小 CompareTime 函数 比较两个日 ...

  5. Android@Home Apple HomeKit

    Android@Home采用基于IEEE802.15.4标准的低功耗个域网协议的ZigBee技术,其是低功耗.低成本及低延迟.标准功率下可满足100米范围内的信号覆盖,并拥有三级安全模式,防止非法获取 ...

  6. VS小技巧

    1."清理解决方案":在对程序进行分发.上传时时常需要压缩解决方案文件夹,这时如果还嫌文件太大,可以在VS里右键解决方案---清理解决方.完成后,则该解决方案下的所有项目的将所有中 ...

  7. POJ 1236 Network of Schools (Tarjan + 缩点)

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12240   Accepted: 48 ...

  8. eclipse dbviewer,eclipse java8

    进入/home/xxx(用户名)/.local/share/applications,看是否有eclipse和深度音乐desktop配置文件,为eclipse.desktop配置图标, 那现在终端输入 ...

  9. Linq中常用的方法

    这几天闲着也是闲着,就仔细的研究了一下Linq的语法,还有他的一些扩展方法的使用. 下面是一些常用的扩展方法. Aggregate 自定义的聚合计算 All 检测序列中所有元素是否都满足指定的条件 A ...

  10. php curl多线程抓取网页

    PHP 利用 Curl Functions 可以完成各种传送文件操作,比如模拟浏览器发送GET,POST请求等等,受限于php语言本身不支持多线程,所以开发爬虫程序效率并不高,这时候往往需 要借助Cu ...