第04天实战技术(15):UICollectionView计算布局尺寸
2017-03-30 00:00
501 查看
#####一、UICollectionView计算布局尺寸
1.添加滚动动画进行缩放
code
取绝对值 fabs
1.添加滚动动画进行缩放
效果:越靠近中心点,距离越小,缩放越大 思路: 0.获取当前显示区域 (self.collectionView.bounds) 1.求cell与中心点的距离 attr.centerX-offsetX-collectionW * 0.5 2.计算比例 (距离越小,缩放越大 所以需要取反) >>> // (attr.center.x - self.collectionView.contentOffset.x) 计算出来是 cell的center.x // cell的center -collectionView的宽度一半 计算出来是 中心点的距离 取绝对值
code
// 可以一次性返回所有cell的尺寸,也可以每隔一个距离返回cell的尺寸 - (nullable NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect { // 设置cell的尺寸 ==> UICollectionViewLayoutAttributes => // 效果越靠近中心点,距离越小,缩放越大 // 求cell与中心点的距离 attr.centerX-offsetX-collectionW * 0.5 // 0.获取当前显示区域 (self.collectionView.bounds) // 1.获取当前显示cell的布局 NSArray *attrs = [super layoutAttributesForElementsInRect:self.collectionView.bounds]; for (UICollectionViewLayoutAttributes *attr in attrs) { // 进行缩放 // 2.计算中心点的距离 (取绝对值) // (attr.center.x - self.collectionView.contentOffset.x) 计算出来是 cell的center.x // cell的center -collectionView的宽度一半 计算出来是 中心点的距离 取绝对值 CGFloat delta = fabs((attr.center.x - self.collectionView.contentOffset.x) - self.collectionView.bounds.size.width * 0.5); // 3.计算比例 (距离越小,缩放越大 所以需要取反) CGFloat scale = 1 - delta / (self.collectionView.bounds.size.width * 0.5) * 0.25; // 1 - 1 * 0.25 = 0.75的缩放比例 attr.transform = CGAffineTransformMakeScale(scale, scale); } return attrs; }
相关文章推荐
- 第04天实战技术(11):UICollectionView基本使用(布局)
- 第04天实战技术(14):UICollectionView自定义布局方法
- 第04天实战技术(10):UICollectionView基本使用
- 第04天实战技术(12):UICollectionView基本使用(抽取方式1)
- 第04天实战技术(13):UICollectionView基本使用(抽取方式2)
- 第03天实战技术(10):UIScrollView的自动布局
- 猫猫学iOS 之微博项目实战(7)程序启动新特性用UICollectionViewController实现
- UICollectionViewCell 布局
- 数学之路-python计算实战(15)-机器视觉-滤波去噪(归一化块滤波)
- iOS8自动调整UITableView和UICollectionView布局---转自http://www.cnblogs.com/xubojoy/p/3933693.html#3016517
- 自定义UICollectionView的布局
- iOS 8自动调整UITableView和UICollectionView布局
- ios自定义View自动布局时计算大小
- iOS- 用UICollectionViewController 来进行横竖屏九宫格布局
- iOS:UICollectionView布局问题
- Android布局性能优化—从源码角度看ViewStub延迟加载技术
- iOS 8自动调整UITableView和UICollectionView布局
- 数学之路-python计算实战(15)-机器视觉-滤波去噪(归一化块滤波)
- 15-UIKit(view布局、Autoresizing)
- 【iOS】UICollectionView自定义Layout之蜂窝布局