cell的动画效果

UICollectionViewCell.gif

今天学习了一种加载UICollectionViewCell的动画效果,具体如图,代码也在下面:

这个效果是cell由小变大

//其实就是在这个方法里为cell添加了一个动画效果
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{

    CATransform3D transform = CATransform3DIdentity;
    transform = CATransform3DRotate(transform, 0, 0, 0, 1);//渐变
    transform = CATransform3DTranslate(transform, 0, -100, 0);//左边水平移动
    transform = CATransform3DScale(transform, 0, 0, 0);//由小变大
    cell.layer.transform = transform;
    cell.layer.opacity = 0.0;
    [UIView animateWithDuration:0.6 animations:^{
        cell.layer.transform = CATransform3DIdentity;
        cell.layer.opacity = 1;
    }];
}

这个效果是cell从左边水平移动进入

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{

    CATransform3D transform = CATransform3DIdentity;
    transform = CATransform3DRotate(transform, 0, 0, 0, 1);//渐变u
    transform = CATransform3DTranslate(transform,-200, 0, 0);//左边水平移动
    transform = CATransform3DScale(transform, 0, 0, 0);//由小变大
    cell.layer.transform = transform;
    cell.layer.opacity = 0.0;
    [UIView animateWithDuration:0.6 animations:^{
        cell.layer.transform = CATransform3DIdentity;
        cell.layer.opacity = 1;
    }];
}
还有一种动画效果
2.gif
//动画代码如下
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    CATransform3D rotation;
    rotation = CATransform3DMakeRotation((90.0 * M_PI) /180, 0.0, 0.7, 0.4);
    rotation.m34 = 1.0/ -600;

    cell.layer.shadowColor = [[UIColor blackColor]CGColor];
    cell.layer.shadowOffset = CGSizeMake(10, 10);
    cell.alpha = 0;
    cell.layer.transform = rotation;
    cell.layer.anchorPoint = CGPointMake(0, 0.5);
    [UIView beginAnimations:@"rotation" context:NULL];
    [UIView setAnimationDuration:0.8];
    cell.layer.transform = CATransform3DIdentity;
    cell.alpha = 1;
    cell.layer.shadowOffset = CGSizeMake(0, 0);
    [UIView commitAnimations];
}
最后一种 先看下效果
3.gif

这个实际上是对label设置的一个动画,不是针对于cell的,具体如下
在自定义的cell实现文件中

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, self.center.y - 15, 150, 50)];
        [self addSubview:self.titleLabel];
    }
    return self;
}
- (void)show{
   [UIView animateWithDuration:1 animations:^{
       self.titleLabel.x = 30;
   }];
}
- (void)hide{
    [UIView animateWithDuration:1 animations:^{
        self.titleLabel.x = 414;
    }];
}

在控制器中的代码

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    AnimationCell *animationCell = (AnimationCell *)cell;
    [animationCell show];
}

- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    AnimationCell *animationCell = (AnimationCell *)cell;
    [animationCell hide];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 参考文章 UITableView中cell点击的绚丽动画效果 效果展示 源码 AnimationCell.h和An...
    刘大帅阅读 4,492评论 1 16
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,588评论 4 61
  • 我自己是个不喜欢写东西的人,尤其是在网络上写东西。具体原因我也不是非常清楚,大概有三个方面吧:一是认为网络上的知识...
    heatven阅读 307评论 0 2
  • 离开了生活了3年的广州,回到了第二故乡,一座美丽的山水城——宜昌。2013年跟随着心爱的人来到他的故乡,结婚生子,...
    简安胡同阅读 314评论 0 1
  • 青春不再来,少年你莫伤怀 时光啊它讲: 当回忆沉淀下来,就会变成豁达的海 装满新的期待 ...... 说到时间,似...
    i图纹系阅读 1,201评论 9 20

友情链接更多精彩内容