博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UICollectionView(二)
阅读量:7265 次
发布时间:2019-06-29

本文共 2141 字,大约阅读时间需要 7 分钟。

3D效果

-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{    NSArray *array = [super layoutAttributesForElementsInRect:rect];    CGRect visibleRect;    visibleRect.origin = self.collectionView.contentOffset;    visibleRect.size = self.collectionView.bounds.size;    for (UICollectionViewLayoutAttributes* attributes in array) {        CGFloat distance = CGRectGetMidX(visibleRect) - attributes.center.x;        NSLog(@"%f",distance);        CGFloat normalizedDistance = distance / ActiveDistance;        CGFloat zoom = 1 + ScaleFactor*(1 - ABS(normalizedDistance));        //3D效果        attributes.transform3D = CATransform3DMakeScale(1.0, zoom, 1.0);        attributes.zIndex = 1;    }    return array;}复制代码

分页

pagingEnabled = true //可根据页面宽度进行分页复制代码

特殊情况下需要根据代理方法去计算分页的距离

- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)offset                                 withScrollingVelocity:(CGPoint)velocity复制代码
- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)offset                                 withScrollingVelocity:(CGPoint)velocity {        CGRect cvBounds = self.collectionView.bounds;    CGFloat halfWidth = cvBounds.size.width * 0.5f;    CGFloat proposedContentOffsetCenterX = offset.x + halfWidth;        NSArray* attributesArray = [self layoutAttributesForElementsInRect:cvBounds];        UICollectionViewLayoutAttributes* candidateAttributes;    for (UICollectionViewLayoutAttributes* attributes in attributesArray) {                // == Skip comparison with non-cell items (headers and footers) == //        if (attributes.representedElementCategory !=            UICollectionElementCategoryCell) {            continue;        }                // == First time in the loop == //        if(!candidateAttributes) {            candidateAttributes = attributes;            continue;        }                if (fabs(attributes.center.x - proposedContentOffsetCenterX) <            fabs(candidateAttributes.center.x - proposedContentOffsetCenterX)) {            candidateAttributes = attributes;        }    }        return CGPointMake(candidateAttributes.center.x - halfWidth, offset.y);    }复制代码

引用

转载地址:http://bxgdm.baihongyu.com/

你可能感兴趣的文章
ADF12C 几种优秀的项目架构
查看>>
设计模式系列--Template
查看>>
jQuery dialog参数详细说明
查看>>
【AngularJS】—— 12 独立作用域
查看>>
PHP 读取PDF文档页数
查看>>
为什么Google急着杀死加密算法SHA-1
查看>>
发表一遍
查看>>
简单排序之冒泡排序
查看>>
Mysql SQL 替换标签内容
查看>>
php笔试题
查看>>
PHP 实现守护进程(Daemon)
查看>>
如何学习linux编程
查看>>
spring data redis 指南
查看>>
Android recovery 模式
查看>>
操作联系人
查看>>
Linux环境配置文件 /etc/profile ~/.bash_profile ~/.bashrc /etc/bashrc的区别
查看>>
HTTP 状态码
查看>>
linux 虚拟机
查看>>
MySQL的Replace into 与Insert into ..... on duplicate
查看>>
ArrayList,LinkedList,Vector
查看>>