Tip: 自己开发了好玩的APP: 《小明搜索》(App Store上搜索:"小明搜索")
[点击下载 "小明搜索"](https://itunes.apple.com/cn/app/小明搜索/id1378798470?l=en&mt=8)
1、集必应、百度、搜狗为一体的搜索平台
2、用户随意收藏或添加自己喜欢的网站
3、网页文字播放功能
4、收藏网页的视频,本地播放
5、附加常用小工具
6、后台播放网页音频
7、3D Touch提供便捷入口
完全自定义的搜索助手,简约的爱不释手~
该APP不断完善中~
#import <UIKit/UIKit.h>@interface CustomFlowLayout : UICollectionViewFlowLayout
@property(nonatomic, assign)IBOutlet id <UICollectionViewDelegateFlowLayout> delegate;
@end
#import "CustomFlowLayout.h"
@interface CustomFlowLayout ()<UICollectionViewDelegateFlowLayout>
@property(nonatomic, strong)NSMutableArray* attributeArray;
@property(nonatomic, strong)UICollectionViewLayoutAttributes* headerAttributes;
@property(nonatomic, strong)UICollectionViewLayoutAttributes* footerAttribytes;
@end
@implementation CustomFlowLayout
- (void)prepareLayout{
self.attributeArray = [[NSMutableArray alloc] init];
[super prepareLayout];
NSInteger numberOfSections = 1;
//行数
if([self.collectionView.dataSource respondsToSelector:@selector(numberOfSectionsInCollectionView:)]){
numberOfSections = [self.collectionView.dataSource numberOfSectionsInCollectionView:self.collectionView];
}
CGFloat totalHeight = 0;
CGFloat itemSpacing = self.minimumInteritemSpacing;
for (int i = 0; i < numberOfSections; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:i];
UIEdgeInsets sectionInset = self.sectionInset;
if([self.delegate respondsToSelector:@selector(collectionView:layout:insetForSectionAtIndex:)]){
sectionInset = [self.delegate collectionView:self.collectionView layout:self insetForSectionAtIndex:i];
}
CGSize sectionHeaderSize = self.headerReferenceSize;
CGSize sectionFooterSize = self.footerReferenceSize;
if([self.delegate respondsToSelector:@selector(collectionView:layout:referenceSizeForHeaderInSection:)]){
sectionHeaderSize = [self.delegate collectionView:self.collectionView layout:self referenceSizeForHeaderInSection:i];
}
if([self.delegate respondsToSelector:@selector(collectionView:layout:referenceSizeForFooterInSection:)]){
sectionFooterSize = [self.delegate collectionView:self.collectionView layout:self referenceSizeForFooterInSection:i];
}
CGFloat colHeight[2] = {0, 0};
UICollectionViewLayoutAttributes* attribute;
if(sectionHeaderSize.height > 0){
attribute = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionHeader withIndexPath:indexPath];
attribute.frame = CGRectMake(sectionInset.left, sectionInset.top + totalHeight, sectionHeaderSize.width, sectionHeaderSize.height);
[self.attributeArray addObject:attribute];
}
if(sectionFooterSize.height > 0){
attribute = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionFooter withIndexPath:indexPath];
attribute.frame = CGRectMake(sectionInset.left, sectionInset.top, sectionFooterSize.width, sectionFooterSize.height);
[self.attributeArray addObject:attribute];
}
totalHeight += sectionHeaderSize.height;
totalHeight += sectionFooterSize.height;
NSInteger numberOfItemsInSection = 0;
if([self.collectionView.dataSource respondsToSelector:@selector(collectionView:numberOfItemsInSection:)]){
numberOfItemsInSection = [self.collectionView.dataSource collectionView:self.collectionView numberOfItemsInSection:i];
}
for (int j = 0; j < numberOfItemsInSection; j++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:j inSection:i];
UICollectionViewLayoutAttributes * attris = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
CGSize size = CGSizeZero;
NSInteger colum = 0;
if([self.delegate respondsToSelector:@selector(collectionView:layout:minimumInteritemSpacingForSectionAtIndex:)]){
itemSpacing = [self.delegate collectionView:self.collectionView layout:self minimumInteritemSpacingForSectionAtIndex:i];
}
if([self.delegate respondsToSelector:@selector(collectionView:layout:sizeForItemAtIndexPath:)]){
size = [self.delegate collectionView:self.collectionView layout:self sizeForItemAtIndexPath:indexPath];
if(colHeight[0] <= colHeight[1]){
colHeight[0] = colHeight[0] + size.height + itemSpacing;
colum = 0;
}else{
colHeight[1] = colHeight[1] + size.height + itemSpacing;
colum = 1;
}
}
attris.frame = CGRectMake(sectionInset.left + (itemSpacing + size.width) * colum, colHeight[colum] - size.height - itemSpacing + totalHeight, size.width, size.height);
[self.attributeArray addObject:attris];
}
CGFloat maxHeight = MAX(colHeight[0], colHeight[1]);
totalHeight += (maxHeight -itemSpacing);
}
}
- (CGSize)collectionViewContentSize{
CGRect frame = [[self.attributeArray lastObject] frame];
return CGSizeMake(self.collectionView.frame.size.width, frame.origin.y + frame.size.height);
}
- (NSArray<UICollectionViewLayoutAttributes*> *)layoutAttributesForElementsInRect:(CGRect)rect{
return self.attributeArray;
}
- (nullable UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath{
return self.headerAttributes;
}
@end
相关推荐
WaterfallFlowLayout瀑布流用重写UICollectionViewFlowLayout类实现Demo; 一下是博客地址 http://blog.csdn.net/margaret_mo/article/details/50581959
通过自定义 UICollectionViewFlowLayout ,实现 UICollectionView 的瀑布流。
最近项目中需要用到瀑布流的效果,但是用UICollectionViewFlowLayout又达不到效果,自己动手写了一个瀑布流的layout,下面是我的心路路程 先上效果图与demo地址: 因为是用UICollectionView来实现瀑布流的,决定...
了解UICollectionView的基本信息以后得知要想实现瀑布流的效果必须使用UICollectionViewLayout,继续参考苹果官方文档了解UICollectionViewFlowLayout必须实现的方法和生命周期。 了解过UICollectionViewFlowLayout的...
源码TLCollectionWaterfallFlow,通过自定义UICollectionViewFlowLayout实现的瀑布流,使用非常简单。 测试环境:Xcode 6.2,iOS 6.0 以上
这段时间突然想到一个很久之前用到的知识-瀑布流,本来想用一个简单的方法,发现自己走入了歧途,最终只能狠下心来重写UICollectionViewFlowLayout.下面我将用两种方法实现瀑布流,以及会介绍第一种实现的bug. 第一种 ...
基于 UICollectionViewFlowLayout 的对齐布局,使用简单,支持以下功能:1. 不同 section 水平方向 items 对齐方式的设置;2. 不同 section 竖直方向 items 对齐方式的设置;3. 不同 section items 排布顺序的设置。...
自定义UICollectionViewFlowLayout ,仿照nice首页,实现左右切换滑动效果,代码简单,几十行,但是效果还可以. git地址:https://github.com/sensejump/RFCircleCollectionView 欢迎star交流~
作者wangxiaocan,源码XCCollectionViewLayout.git,UICollectionView滑动放大、仿射变换、瀑布流效果
以前瀑布流的时候使用过UICollectionView,但是那时使用的是系统自带的UICollectionViewFlowLayout布局,今天看文章,看到UICollectionViewFlowLayout自定义相关的东西,于是动手写了一个简单图片浏览的demo,熟练...
UICollectionViewLayout各种布局三种有趣的布局,线性布局,圆形布局,格子布局App首页布局 @class LMJElementsFlowLayout;@protocol LMJElementsFlowLayoutDelegate < NSObject>@required/* * * 要求实现 * * @...
按钮实现界面横向和瀑布流布局,UICollectionViewFlowLayout是Apple为我们准备的开袋即食的现成布局,因此之前提到的几个必须重载的方法中需要我们操心的很少,即使完全不重载它们,现在也可以得到一个不错的线状一...
封装 UICollectionViewFlowLayout ,使实现 UICollectionView 动画更简单
重新UICollectionViewFlowLayout实现缩放滚动效果 更多优秀Demo请访问GitHub github地址:https://github.com/mengzhihun6
自定义UICollectionViewFlowLayout实现横向翻页横向数据,demo为一个通用的图片选择视图,简单易用,一句代码就能实现
SHCollectionViewFlowLayout通过瀑布流UICollectionView实现类似于iOS原生短信界面的弹簧效果#使用方法导入SHCollectionViewFlowLayout到你自己项目中,舍弃系统的UICollectionViewFlowLayout.具体看demo弹簧效果的...