CAKeyframeAnimation keyframe animation senior animation of iOS

1 Rock the realization of animation

CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];

 CGFloat angel = M_PI_4 / 12.0;

 [anim setValues:@[@(angel), @(-angel), @(angel)]];

[Anim setrepeatcount: HUGE_VALF];

 [Self.anima.layer addAnimation six forKey: nil];

2 Bezier curve to achieve animation

  // 1. Examples of key-frame animation
    CAKeyframeAnimation Anim * = [CAKeyframeAnimation animationWithKeyPath: @ "position"];
    
    // set the path 2.
    [anim setDuration: duration];
    
    give // random points on the screen using the intermediate control points
    CGPoint cp = [Self randomPoint];
    
    CGMutablePathRef CGPathCreateMutable path = ();
    
    // set the starting point
    CGPathMoveToPoint (path, NULL, self.center.x, self.center.y);
    // add with a control point Bezier curve
    CGPathAddQuadCurveToPoint (path, NULL, cp.x, cp.y, to.x, to.y);
    
    [Anim setPath: path];
    CGPathRelease (path);
    
    //. 5) records the setting key target position to the end of the animation, correction position
    [Anim setValue: @ "translationTo" forKey: @ "animationType"];
    [Anim setValue: [NSValue valueWithCGPoint: to] forKey: @ "targetPoint"];
    [Anim setDelegate: Self];
    
    // add animation to the layer 3.
    [self.layer addAnimation: anim forKey: nil ];

Published 368 original articles · won praise 22 · Views 200,000 +

Guess you like

Origin blog.csdn.net/BianHuanShiZhe/article/details/104972339