LSAnimator icon indicating copy to clipboard operation
LSAnimator copied to clipboard

CAKeyframeAnimation动画怎么搞?

Open vitasapple opened this issue 3 years ago • 0 comments

比如这个震动效果的动画要怎么写?

    CAKeyframeAnimation * anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    anim.values = @[[NSValue valueWithCGPoint:CGPointMake(targetV.center.x, targetV.center.y)],
                    [NSValue valueWithCGPoint:CGPointMake(targetV.center.x, targetV.center.y + 1)],
                    [NSValue valueWithCGPoint:CGPointMake(targetV.center.x+1, targetV.center.y - 1)],
                    [NSValue valueWithCGPoint:CGPointMake(targetV.center.x-1, targetV.center.y + 1)]];
    anim.duration = 0.2;
    anim.repeatCount = 5;
    anim.removedOnCompletion = YES;
    [targetV.layer addAnimation:anim forKey:@"shake"];

vitasapple avatar Jun 04 '21 03:06 vitasapple