• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CAKeyframeAnimation problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CAKeyframeAnimation problem


  • Subject: CAKeyframeAnimation problem
  • From: "David W. Berry" <email@hidden>
  • Date: Sun, 12 Jul 2009 16:17:03 -0500

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
email@hidden



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: CAKeyframeAnimation problem
      • From: David Duncan <email@hidden>
  • Prev by Date: iPhone sdk 3.0 -> MKMapView linker error
  • Next by Date: Re: Best 'Cocoa' File Preview
  • Previous by thread: iPhone sdk 3.0 -> MKMapView linker error
  • Next by thread: Re: CAKeyframeAnimation problem
  • Index(es):
    • Date
    • Thread