头像抖动动画效果

项目中用到某一个状态下的cell上添加头像抖动动画,记录一下。

  1. 在自定义cell上描述边框

- (void)customView:(AAItemCollectionViewCell *)cell indexPath:(NSIndexPath *)indexPath{
    if (indexPath.row != 0 || ![cell.titleLabel.text isEqualToString:@"直播中"]) {
        return;
    }
    [cell removeFromSuperview];
    self.animateTime = 0.4;
    
    // 固定边框
    UIView *borderView = [[UIView alloc] init];
    borderView.layer.cornerRadius = 69/2.0;
    borderView.layer.borderColor = MainColor.CGColor;
    borderView.layer.borderWidth = 1;
    [cell.scaleView addSubview:borderView];
    [borderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(cell.scaleView);
    }];
    
    // 缩放边框
    UIView *borderZoomView = [[UIView alloc] init];
    borderZoomView.layer.cornerRadius = 69/2.0;
    borderZoomView.layer.borderColor = [MainColor colorWithAlphaComponent:0.8].CGColor;
    borderZoomView.layer.borderWidth = 1;
    [cell.scaleView addSubview:borderZoomView];
    [borderZoomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(cell.scaleView);
    }];
    cell.scaleView = borderZoomView;
    
    // 缩放动画
    [self zoomView:cell];
}
  1. 添加抖动动画效果

// 核心代码
- (void)zoomView:(AAItemCollectionViewCell *)cell {
    // 具体缩放大小 效果根据需要自己调整
    // 边框放大
    [UIView animateWithDuration:self.animateTime+0.1 animations:^{
        cell.scaleView.transform = CGAffineTransformMakeScale(1.15, 1.15); // 边框放大
        cell.scaleView.alpha = 0.08; // 透明度渐变
    } completion:^(BOOL finished) {
        // 恢复默认
        cell.scaleView.transform = CGAffineTransformMakeScale(1, 1);
        cell.scaleView.alpha = 1;
    }];
    
    // imageView先缩小 再恢复
    [UIView animateWithDuration:self.animateTime animations:^{
        cell.headImageView.transform = CGAffineTransformMakeScale(0.88, 0.88); // 缩小
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:self.animateTime animations:^{
            cell.headImageView.transform = CGAffineTransformMakeScale(1, 1); // 放大
        } completion:^(BOOL finished) {
            // 重新调用
            [self zoomView:cell];
        }];
    }];
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值