開始動畫
CALayer *_layer;
- 設置動畫過程(注意動畫的過程是移動一個ImageView)
//添加加入購物車動畫
- (void)addAnimationPath:(HSGoodsListTableViewCell *)cell
{
HSGoodsListTableViewCell *bolthCell=(HSGoodsListTableViewCell *)cell;
_layer = [CALayer layer];
_layer.contentsGravity = kCAGravityResizeAspectFill;
UIImageView *imagV = bolthCell.goodsImage;
_layer.contents = (id)imagV.layer.contents;
CGRect frame = [bolthCell.goodsImage convertRect:bolthCell.goodsImage.frame toView:self.view];
_layer.bounds=frame;
CGPoint p=[bolthCell.goodsImage convertPoint:bolthCell.goodsImage.center toView:self.view];
//創建貝塞爾曲線
UIBezierPath *bPath=[UIBezierPath bezierPath];
[bPath moveToPoint:p];
[bPath addQuadCurveToPoint:CGPointMake(shopCarBtnCenter.x,shopCarBtnCenter.y) controlPoint:CGPointMake(shopCarBtnCenter.x, p.y)];
[self groupAnimation:bPath];
[self.view.layer addSublayer:_layer];
}
//構建一組動畫
-(void)groupAnimation:(UIBezierPath *)path
{
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = path.CGPath;
animation.rotationMode = kCAAnimationRotateAuto;
//動畫縮小
CABasicAnimation *narrowAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
narrowAnimation.beginTime = 0;
narrowAnimation.fromValue = [NSNumber numberWithFloat:0.6f];
narrowAnimation.duration = 0.5f;
narrowAnimation.toValue = [NSNumber numberWithFloat:0.1f];
narrowAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
//動畫組建
CAAnimationGroup *groups = [CAAnimationGroup animation];
groups.animations = @[animation,narrowAnimation];
groups.duration = 0.5f;
groups.removedOnCompletion=YES;
groups.fillMode=kCAFillModeForwards;
groups.delegate = self;
//根據路線畫路線或填充
[_layer addAnimation:groups forKey:nil];
}
//移除動畫
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
[_layer removeFromSuperlayer];
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。