Note that there are some explanatory texts on larger screens.

plurals
  1. POHow Do You CAKeyframeAnimation Scale?
    primarykey
    data
    text
    <p>I want to create an animation with several key frames. I want my Layer (a button in this case) to scale up to 1.5 then down to 0.5 then up to 1.2 then down to 0.8 then 1.0.</p> <p>I also want to EaseIn and EaseOut of each keyframe.</p> <p>As you can imagine, this will create a Springy/Bounce effect on the spot.</p> <p>In other parts of my app I have been using CAKeyframeAnimation like this (see below code). This creates a similar springy animation but for x and y position.</p> <p><strong>Can I adapt the below code to affect scale instead of position?</strong></p> <p>Thank you in advance!</p> <pre><code>- (CAAnimation*)monInAnimation { CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path,NULL,113,320); CGPathAddLineToPoint(path, NULL, 113.5, 283); CGPathAddLineToPoint(path, NULL, 113.5, 179); CGPathAddLineToPoint(path, NULL, 113.5, 207); CGPathAddLineToPoint(path, NULL, 113.5, 187); CGPathAddLineToPoint(path, NULL, 113.5, 199); CGPathAddLineToPoint(path, NULL, 113.5, 193); CGPathAddLineToPoint(path, NULL, 113.5, 195); CGPathAddLineToPoint(path, NULL, 113.5, 194); CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; [animation setPath:path]; [animation setDuration:1.5]; [animation setCalculationMode:kCAAnimationLinear]; NSArray *arr = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.12], [NSNumber numberWithFloat:0.24], [NSNumber numberWithFloat:0.36], [NSNumber numberWithFloat:0.48], [NSNumber numberWithFloat:0.60], [NSNumber numberWithFloat:0.72], [NSNumber numberWithFloat:0.84], [NSNumber numberWithFloat:1.0],nil]; [animation setKeyTimes:arr]; [animation setTimingFunctions:[NSArray arrayWithObjects:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], nil]]; //[animation setAutoreverses:YES]; CFRelease(path); return animation; </code></pre> <p>}</p> <pre><code>- (void)monBtnIn { [monButton.layer setPosition:CGPointMake(113.5,194)]; [monButton.layer addAnimation:[self monInAnimation] forKey:@"position"]; </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload