给TableView或者CollectionView的cell添加简单动画
2016-06-30 10:43
405 查看
只要在willDisplayCell方法中对将要显示的cell做动画即可:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
NSArray *array = tableView.indexPathsForVisibleRows;
NSIndexPath *firstIndexPath = array[0];
//设置anchorPoint
cell.layer.anchorPoint = CGPointMake(0,
0.5);
//为了防止cell视图移动,重新把cell放回原来的位置
cell.layer.position = CGPointMake(0, cell.layer.position.y);
//设置cell
按照z轴旋转90度,注意是弧度
if (firstIndexPath.row < indexPath.row) {
cell.layer.transform = CATransform3DMakeRotation(M_PI_2,
0, 0,
1.0);
}else{
cell.layer.transform = CATransform3DMakeRotation(-
M_PI_2, 0,
0, 1.0);
}
cell.alpha = 0.0;
[UIView animateWithDuration:1 animations:^{
cell.layer.transform = CATransform3DIdentity;
cell.alpha = 1.0;
}];
}
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row %
2 != 0) {
cell.transform = CGAffineTransformTranslate(cell.transform, kScreenWidth/2,
0);
}else{
cell.transform = CGAffineTransformTranslate(cell.transform, -kScreenWidth/2,
0);
}
cell.alpha = 0.0;
[UIView animateWithDuration:0.7 animations:^{
cell.transform = CGAffineTransformIdentity;
cell.alpha = 1.0;
} completion:^(BOOL finished) {
}];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
NSArray *array = tableView.indexPathsForVisibleRows;
NSIndexPath *firstIndexPath = array[0];
//设置anchorPoint
cell.layer.anchorPoint = CGPointMake(0,
0.5);
//为了防止cell视图移动,重新把cell放回原来的位置
cell.layer.position = CGPointMake(0, cell.layer.position.y);
//设置cell
按照z轴旋转90度,注意是弧度
if (firstIndexPath.row < indexPath.row) {
cell.layer.transform = CATransform3DMakeRotation(M_PI_2,
0, 0,
1.0);
}else{
cell.layer.transform = CATransform3DMakeRotation(-
M_PI_2, 0,
0, 1.0);
}
cell.alpha = 0.0;
[UIView animateWithDuration:1 animations:^{
cell.layer.transform = CATransform3DIdentity;
cell.alpha = 1.0;
}];
}
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row %
2 != 0) {
cell.transform = CGAffineTransformTranslate(cell.transform, kScreenWidth/2,
0);
}else{
cell.transform = CGAffineTransformTranslate(cell.transform, -kScreenWidth/2,
0);
}
cell.alpha = 0.0;
[UIView animateWithDuration:0.7 animations:^{
cell.transform = CGAffineTransformIdentity;
cell.alpha = 1.0;
} completion:^(BOOL finished) {
}];
}
相关文章推荐
- GreenDao的简单使用说明(四)特殊的单表1:n
- Quartz
- Qt学习九:控件六:任务栏托盘菜单
- 编程常见的技术和管理诟病
- struts自定义验证规则
- 你手机注册过哪些网站,测一测
- DataStage最佳实践之存储过程调用
- 代码查找
- 适配器模式
- 工厂模式与老化模式驱动中分别添加内容
- spring使用模板发送邮件
- Retrofit的(get以及post)的简单使用
- GreenDao的简单使用说明(三)多表的操作1:n
- js 对时间格式化
- Oracle递归查询:使用prior实现树操作
- 自制的Docker镜像
- Android事件总线分发库的使用EventBus(和Otto一样,只是效率高点)
- SQL Case When 嵌套
- Android上传文件到FTP
- 【leetcode】24. Swap Nodes in Pairs