为tableView添加动画

14425B30a2I0-NB5.jpg

在cell将要展示的时候做一个动画,只需要把这段代码放在tablew的代理方法一起就OK了

- (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)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
// 1. 配置CATransform3D的内容
CATransform3D transform;
transform = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);
transform.m34 = 1.0/ -600;

// 2. 定义cell的初始状态
cell.layer.shadowColor = [[UIColor blackColor]CGColor];
cell.layer.shadowOffset = CGSizeMake(10, 10);
cell.alpha = 0;

cell.layer.transform = transform;
cell.layer.anchorPoint = CGPointMake(0, 0.5);

// 3. 定义cell的最终状态,并提交动画
[UIView beginAnimations:@"transform" context:NULL];
[UIView setAnimationDuration:0.5];
cell.layer.transform = CATransform3DIdentity;
cell.alpha = 1;
cell.layer.shadowOffset = CGSizeMake(0, 0);
cell.frame = CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);
[UIView commitAnimations];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,786评论 4 61
  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,473评论 30 472
  • 不知道要写些什么,写了又删,删了又写,我好像很长时间都没有这样坐下来为我自己做点什么事情了。 现在,我坐在这,很静...
    美美雪阅读 1,702评论 0 0
  • “ 英文部分来自经济学人,译文仅供个人研习、欣赏语言之用,谢绝任何转载及用于任何商业用途。本译文所涉法律后果均由本...
    柠檬一小颗阅读 3,863评论 0 2
  • 这一走,又是一年。好遥远,好遥远,眼泪不争气想往下掉,也不是没有分别过,可是依然没有习惯,对你的依赖感只会因你的态...
    努力的小暖阅读 1,427评论 0 0

友情链接更多精彩内容