给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) {

   }];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • iOS10个实用小技巧(总有你不知道的和你会用到的) 字数1838阅读4960评论53喜欢267 在开发过程中我们...
    假行_僧阅读 698评论 0 2
  • 1.NSString过滤特殊字符串定义一个特殊字符的集合NSCharacterSet set = [NSChara...
    奋拓达阅读 769评论 0 0
  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 9,093评论 3 38
  • 还记得你曾经的模样吗?天真彷徨。你看到你现在的模样了吗?辛酸刻薄。我们到底是因为什么变成了这样。 从来不去批判某...
    如故长风来阅读 566评论 0 0
  • ①前些日子闲来无事 看了看中国好歌曲 这个挺流行的选秀节目 最大的特点就是歌曲完全由学员自创 听了一首歌叫做《猪...
    衿泷阅读 840评论 0 3