I'm having a problem with CAKeyframeAnimation in an iPhone application
I'm developing. I'm using several flash-card style animations which
just play a sequence of images created by chopping up a .png file.
The animation creation looks like:
- (id) initFromDescription:(NSDictionary*)description withCache:
(GWImageCache*)cache
{
if((self = [super init]) != nil)
{
double duration = 0.;
NSMutableArray* frames = [NSMutableArray
arrayWithCapacity:5];
NSMutableArray* times = [NSMutableArray
arrayWithCapacity:5];
for(NSDictionary* frame in [description
objectForKey:@"children"])
{
if([[frame objectForKey:@"name"]
isEqualToString:@"frame"])
{
NSDictionary* attributes = [frame
objectForKey:@"attributes"];
NSString* strBounds = [attributes
objectForKey:@"bounds"];
NSString* strDelay = [attributes
objectForKey:@"delay"];
UIImage* image = [cache imageWithFile:[attributes
objectForKey:@"file"]];
double delay = 1. / 30.;
if(strBounds)
{
CGRect bounds =
CGRectFromString(strBounds);
CGImageRef original =
image.CGImage;
CGImageRef copy =
CGImageCreateWithImageInRect(original, bounds);
[frames addObject:(id)copy];
CFRelease(copy);
}
else
{
[frames addObject:(id)image.CGImage];
}
if(strDelay)
{
delay = [strDelay doubleValue] / 1000.;
}
[times addDouble:delay];
duration += delay;
}
}
double cumulative = 0.;
for(int i = 0 ; i < times.count ; ++i)
{
double time = [times doubleAtIndex:i];
[times replaceObjectAtIndex:i withDouble:cumulative /
duration];
cumulative += time;
}
[self setKeyPath:@"contents"];
[self setDuration:duration];
[self setValues:frames];
[self setKeyTimes:times];
[self setCalculationMode:kCAAnimationDiscrete];
[self setRemovedOnCompletion:YES];
[self setRepeatCount:1.];
}
return self;
}
So the jist of it is that I create a subclass of CAKeyframeAnimation
that has a sequence of images in it's values property and a sequence
of frame durations in the keyTimes property. I can then add the
animation to a layer to display and that's where the problem arises.
The first time (and only the first time) the animation is played the
first few frames don't display (the movies are short, they only
consist of 3-12 frames at 15fps) After the first time I play the
animation and it fails, I can play the animation just fine.
Each animation is just created one time, but the layer in which the
animation is played is created each time I play the animation.
David W. Berry
d...@greenwing.com
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com