1

As I know, putting it simply, Core Animation actually works by interpolating property value over time. Given this, is there any way to interpolate the property to a specific time? For example I have animation

animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.duration = 1.0;
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat:1.0];

Is there a way to freeze the layer at, say, 0.5 seconds when the opacity value is also 0.5?

If there's no way to do it with Core Animation, are there any tweening library for objective-c that allows this?

vangoz
  • 546
  • 6
  • 15

3 Answers3

0

It is possible to freeze an animation by setting it's speed property to 0. It might be possible to freeze an animation, and then change it's beginTime property or timeOffset property.

The docs on both these properties is really bad. Check out this link for better information:

Time warp animation

Duncan C
  • 128,072
  • 22
  • 173
  • 272
0

The open source INTUAnimationEngine library will do exactly what you want.

It provides an API that looks very much like the block-based animation API on UIView, here's the most basic variant:

// INTUAnimationEngine.h

// ...

+ (INTUAnimationID)animateWithDuration:(NSTimeInterval)duration
                                 delay:(NSTimeInterval)delay
                            animations:(void (^)(CGFloat percentage))animations
                            completion:(void (^)(BOOL finished))completion;

// ...

The important difference is that the animations block you pass to INTUAnimationEngine will be executed once every frame of the animation, and the percentage (or progress) value passed into the animations block each time reflects the current state of the animation.

So you can easily use this to do whatever custom interpolation, tweening, or other logic you need to do.

smileyborg
  • 30,197
  • 11
  • 60
  • 73
-1

You can use keyframe animation with Core Animation.

Here is a tutoirial

Simon Lee
  • 22,304
  • 4
  • 41
  • 45
  • What I want is not keyframe animation. I want a basic animation that can be interpolated to certain state at will. Let's say I have made a 1 sec basic animation, and I want the target to be in the same state as it would be after animating 0.3 sec, by simply stating "interpolate to 0.3" or something. – vangoz Jan 24 '12 at 09:59