举一反三 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著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 最近做项目接触了一 ...
随机推荐
- PostgreSQL查询数据(连接查询和子查询)
原料 --用户表 create table "SysUser"( "UserId" serial, --用户Id,自增 "UserName" ...
- ES6学习之let声明变量的学习
1.let和var类似, (1)let与var不同的点:let没有预编译,变量提升这个过程,let声明的变量只能在当前作用域内访问到(一个{}可以看做是一个作用域),在全局var声明的变量属于wind ...
- Android - Telephony API 1.5
TelephonyManager: 1. public String getDeviceSoftwareVersion() : software version number, ex: IMEI/SV ...
- Android 如何保存资源 Id 数组在 res/values/arrays.xml 里
<resources> <!-- Tracks Information --> <array name="music_ids"> <ite ...
- NTP服务器配置
#/etc/ntp.conf# driftfile /var/lib/ntp/ntp.drift logfile /var/log/ntpd.log statistics loopstats peer ...
- 常见的vue面试题
001.v-show与v-if的区别v-show:操作的是元素的display属性 v-if:操作的是元素的创建和插入相比较而言v-show的性能要高 002.methods.computed.wat ...
- 学习xss模拟构造攻击(第一篇)
本文作者:i春秋签约作家——rosectow 0×00前言 XSS又名叫CSS全程(cross site scriptting),中文名跨站脚本攻击,目前网站的常见漏洞之一,它的危害没有像上传漏洞,s ...
- iOS没你想的那么安全?
iOS应用由于直接运行在用户的手机上,而不是运行在后台服务器上,所以更容易被攻击. 任何系统都会有木马病毒的产生,不存在绝对的安全,iOS应用由于直接运行在用户的手机上,而不是运行在后台服务器上,所以 ...
- DBHelper--Java JDBC SSH 连接数据库工具类
概述 JDBC 指 Java 数据库连接,是一种标准Java应用编程接口( JAVA API),用来连接 Java 编程语言和广泛的数据库. ----------------------------- ...
- 【Quartz】解密properties配置文件中的账号密码
在配置quartz时,为了保密某些信息(特别是账号密码),通常会使用密文.那么在实际使用这些配置信息时,需要进行解密.本文提供一种解密方法如下: (1)假设在properties文件中加密了账号密码 ...