项目中用到某一个状态下的cell上添加头像抖动动画,记录一下。
在自定义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];
}
添加抖动动画效果
// 核心代码
- (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];
}];
}];
}