举一反三 willDisplayCell在UICollectionView中的一些应用
一、UICollectionViewCell动画
上一篇博客写仿58同城实现UITableViewCell动画,同样UiCollectionView中也能用,上一个是从右到左的动画还比较好弄, 但如果ScrollView滑动方向时垂直的,动画方向也是垂直的话那就有一些要注意的了,因为Cell的frame是根据父视图ScrollView的ContentSize、偏移量、ContentInset决定的,所以设置frame.Y要特别注意.x也要注意不能使用0.
// // ViewController.m // CollectionCell // // Created by City--Online on 15/11/9. // Copyright © 2015年 City--Online. All rights reserved. // #import "ViewController.h" @interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout> @property(nonatomic,strong) UICollectionView *collectionView; @property (nonatomic,strong) NSMutableArray *showedIndexPaths; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; _showedIndexPaths=[[NSMutableArray alloc]init]; )/; UICollectionViewFlowLayout *collectionViewFlowLayout=[[UICollectionViewFlowLayout alloc]init]; collectionViewFlowLayout.minimumInteritemSpacing=1.0; collectionViewFlowLayout.minimumLineSpacing=0.0; collectionViewFlowLayout.scrollDirection = UICollectionViewScrollDirectionVertical; collectionViewFlowLayout.sectionInset = UIEdgeInsetsMake(, 0.0); collectionViewFlowLayout.itemSize=CGSizeMake(itemWidth, itemWidth); collectionViewFlowLayout.estimatedItemSize=CGSizeMake(itemWidth, itemWidth); collectionViewFlowLayout.scrollDirection=UICollectionViewScrollDirectionVertical; collectionViewFlowLayout.headerReferenceSize=CGSizeMake(, ); collectionViewFlowLayout.footerReferenceSize=CGSizeMake(, ); _collectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(, self.view.bounds.size.height-itemWidth*, self.view.bounds.size.width, itemWidth*) collectionViewLayout:collectionViewFlowLayout]; _collectionView.backgroundColor=[UIColor whiteColor]; _collectionView.delegate=self; _collectionView.dataSource=self; _collectionView.allowsSelection=YES; _collectionView.allowsMultipleSelection=YES; [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"]; [self.view addSubview:_collectionView]; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { ; } //单元格 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; cell.backgroundColor = [UIColor colorWithRed:arc4random()%/ / / ]; return cell; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { ; } - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath { if ([_showedIndexPaths containsObject:indexPath]) { return; } else { [_showedIndexPaths addObject:indexPath]; NSLog(@"%@",NSStringFromCGRect(cell.frame)); CGRect toFrame=cell.frame; //Y ScrollView滑动到底部的时的Y cell.frame=CGRectMake(cell.frame.origin.x,_collectionView.contentSize.height+_collectionView.contentOffset.y+_collectionView.contentInset.top, cell.bounds.size.width, cell.bounds.size.height); cell.layer.cornerRadius=cell.bounds.size.width/; [UIView animateWithDuration:(indexPath.row)* options:UIViewAnimationOptionCurveEaseIn animations:^{ cell.frame=toFrame; } completion:^(BOOL finished) { }]; } } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"%@",indexPath); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
效果图:
二、仿百度 右边一个Cell,左边两个Cell
在一些APP中也会有下面右边一个Cell,左边两个Celll类似的布局,除了用UICollectionViewFlowLayout自定义外,简单一点就可以在willDisplayCell中改变Cell的frame。
举一反三 willDisplayCell在UICollectionView中的一些应用的更多相关文章
- 怎样在UICollectionView中添加Header和footer
---恢复内容开始--- 怎样在UICollectionView中添加Header和footer 转载于http://my.oschina.net/zboy/blog/221525 摘要 来自-htt ...
- 记一次UICollectionView中visibleCells的坑
记一次UICollectionView中visibleCells的坑 项目的要求是这样的 其实也是一个轮播图,而已,所以依照轮播图的实现原理,这里觉得也很简单,还是利用UICollectionView ...
- UICollectionView中使用 UICollectionViewFlowLayout进行布局(模仿苹果相册)
现在都知道,在初始化UICollectionView的时候,必须要传入一Layout对象,进行布局管理.这也是collectionview和tableview的明显区别,通过collectionvie ...
- StroyBoard中UICollectionView中添加Header和footer
到Storyboard中,选择collection view controller中的"Collection View".在Attributes inspector中,选择&quo ...
- UICollectionView中的cell 左对齐
项目中使用UICollectionView做布局,会发现当某个section只有一个cell的时候cell会居中显示,而项目中都是居左显示,这就需要对UICollectionView的布局做些处理,首 ...
- IOS中集合视图UICollectionView中DecorationView的简易使用方法
转载自: http://www.it165.net/pro/html/201312/8575.html Decoration View是UICollectionView的装饰视图.苹果官方给的案例 ...
- UICollectionView中的cell包含UIScrollview
需求:在scrollview的子View不为0,当scrollview的展示的index不为0且向右滑动CollectionView.CollectionView不滑动Cell,而是让scrollvi ...
- UICollectionView中Cell左对齐 居中 右对齐 等间距------你想要的,这里都有
支持靠左,居中,靠右,等间距对齐. 靠左等间距.png 居中等间距.png 靠右等间距.png #import <UIKit/UIKit.h> typedef NS_ENUM(NSInte ...
- iOS中的界面多选功能--(UICollectionView)
文/Jacob_Pan(简书作者)原文链接:http://www.jianshu.com/p/9d28ebd0f5a2著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 最近做项目接触了一 ...
随机推荐
- EF查询记录
public void TestMethod1() { , Ids = , Ids = "4,5,6" } }; , , , , , , , }; var query = quer ...
- C# 时间戳与DateTime间的互相转换
//DateTime转换为时间戳public long GetTimeSpan(DateTime time) { DateTime startTime = TimeZone.CurrentTimeZo ...
- 「BZOJ4318」OSU!
题目链接 戳我 \(Solution\) 我们考虑每增加一个\(1\)会对答案有什么影响: \[E((x+1)^3)-E(x^3)=E(3x^2+3x+1)=3E(x^2)+3E(x)+1\] 所以我 ...
- django系列8.3--django中间件实现登录验证(1)
中间件版的登录验证需要依靠session,所以数据库中要有django_session表. urls.py from django.conf.urls import url from app01 im ...
- 【汉化】Acunetix Web Vulnerability Scanner 11.x汉化包
破解补丁::http://www.52pojie.cn/thread-609275-1-1.html 汉化界面截图: 登陆界面 仪表盘 目标 漏洞 扫描 用户配置 汉化详情: 1.对UI界面大部分 ...
- ionic 项目 随笔
1,首先 会进入src/index.html, <!-- The polyfills js is generated during the build process --> <sc ...
- python获取aliyun ECS实例
#!/usr/bin/env python #-*- coding:utf-8 -*- # Description : get ecs from aliyun # Author : quke # Da ...
- [Objective-C语言教程]类别(28)
有时,可能会发现希望通过添加仅在某些情况下有用的行为来扩展现有类. 要向现有类添加此类扩展,Objective-C提供了类别和扩展. 如果需要向现有类添加方法,或许为了添加功能以便在应用程序中更容易地 ...
- JVM调优总结 -Xms -Xmx -Xmn -Xss(转自:iteye unixboy)
堆大小设置JVM 中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-bit)限制:系统的可用虚拟内存限制:系统的可用物理内存限制.32位系统下,一般限制在1.5G~2G:64为操作 ...
- java开发注解大全
目录 1.最基础注解(spring-context包下的org.springframework.stereotype) 1.1.@Controller @Service @Repository @Co ...