自定义UICollectionViewLayout
2016-01-04 20:26
399 查看
扎堆布局效果
![](http://img.blog.csdn.net/20160104202453463?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
// // StackLayout.h // 自定义UICellectionView布局 #import <UIKit/UIKit.h> @interface StackLayout : UICollectionViewLayout @end
// // StackLayout.m // 自定义UICellectionView布局 #import "StackLayout.h" @implementation StackLayout - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { return YES; } - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { NSArray *angles = @[@0, @(-0.2), @(-0.5), @(0.2), @(0.5)]; UICollectionViewLayoutAttributes *attrs = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; attrs.size = CGSizeMake(100, 100); attrs.center = CGPointMake(self.collectionView.frame.size.width * 0.5, self.collectionView.frame.size.height * 0.5); if (indexPath.item >= 5) { attrs.hidden = YES; } else { attrs.transform = CGAffineTransformMakeRotation([angles[indexPath.item] floatValue]); // zIndex越大,就越在上面 attrs.zIndex = [self.collectionView numberOfItemsInSection:indexPath.section] - indexPath.item; } return attrs; } - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { NSMutableArray *array = [NSMutableArray array]; NSInteger count = [self.collectionView numberOfItemsInSection:0]; for (int i = 0; i<count; i++) { UICollectionViewLayoutAttributes *attrs = [self layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]]; [array addObject:attrs]; } return array; } @end
相关文章推荐
- hibernate Query list()的缓存问题
- 自定义UICollectionViewFlowLayout
- this class is not key value coding-compliant for the key xxxxx.
- build.gradle_2.5
- queue implement
- iOS原生的搜索:UISearchController
- 控制器生命周期和 UIView
- UIView
- easyUI datagrid
- 深度剖析之 GuideBackgroundColorAnimation
- UI控件之UITableView
- UI测试常见BUG汇总——适用于新手
- iOS UIView的clipsTobounds属性
- Maximum Value二分二分 暴力暴力
- PHP之include/require深入了解
- UI基础类 UIView
- iOS8开发~UI布局(三)深入理解autolayout
- iOS8开发~UI布局(二)storyboard中autolayout和size class的使用详解
- iOS8开发~UI布局(一)初探Size Class
- msm8660 ics lcd blueScreen issue