• 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
CAAnimationGroup doesn't do all animations
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CAAnimationGroup doesn't do all animations


  • Subject: CAAnimationGroup doesn't do all animations
  • From: Joachim <email@hidden>
  • Date: Sun, 20 Jan 2008 17:49:28 +0100

Boy, this CoreAnimation doesn't come easy to me...

I'm struggling with CAAnimationGroup in conjunction with - actionForKey:, kCAOnOrderIn...

I like the ability to override implicit animations by providing custom -actionForLayer:forKey:. This way I can simply add my sublayer to the rootlayer, and my animation/transition will automatically kick in. In this case I'd like them fade in while popping. But when I attempt this, only the fade-in seems to be executed. The code in my CALayer subclass looks something like this:

+ (id)layerWithInfo:(MyInfoClass *)info
{
MyLayerClass *layer = (MyLayerClass *)[super layer];
layer.info = info;

// Configure layer, based on info data; turn off animation while configuring
// [snip
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
layer.anchorPoint = CGPointMake (0, 0); // Use lower/left corner as with views
layer.frame = CGRectMake (0, 0, 40, 40);
layer.contents = aCGImageRef;
layer.delegate = layer; // So we can provide custom impicit animations
[CATransaction setValue:(id)kCFBooleanFalse forKey:kCATransactionDisableActions];

return layer;
}


- (id<CAAction>)actionForKey:(NSString *)key
{
// Return default animations for various events and properties
if ([key isEqualToString:kCAOnOrderIn])
{
// Create and configure a basic animation for the fade in
// Use key path since we'll be in a group.
CABasicAnimation *alphaAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
alphaAnim.fromValue = [NSNumber numberWithFloat:0.0];
alphaAnim.toValue = [NSNumber numberWithFloat:1.0];

// Create keyframe animation for the pop effect
CAKeyframeAnimation *sizeAnim = [CAKeyframeAnimation animationWithKeyPath:@"frame"];

// Calculate rectangle sizes and frames for the various states
NSRect endRect = NSMakeRect (0, 0, 40, 40);
NSRect startRect = NSMakeRect (NSMidX (endRect), NSMidY (endRect), 0, 0); // zero-rect
NSRect popRect = NSInsetRect (endRect, -10, -10);

// Create array of values for animation
NSArray *values = [NSArray arrayWithObjects:
[NSValue valueWithRect:startRect],
[NSValue valueWithRect:popRect],
[NSValue valueWithRect:endRect],
nil];
sizeAnim.values = values;

// Create array of key times for animation
NSArray *times = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.8],
[NSNumber numberWithFloat:1.0],
nil];
sizeAnim.keyTimes = times;

// Put the two animations together into one animation group
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = [NSArray arrayWithObjects:alphaAnim, sizeAnim, nil];
group.duration = 3.0;

return group;
}
else if ([key isEqualToString:@"position"])
{
// Move layer to new position
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:key];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.duration = self.moveDuration; // Calculated in the calling code
return anim;
}
else
return nil;
}


In my view code I then just call:
	layer = [MyLayerClass layer];
	[self.layer addSublayer:layer];

So why does my layer only animate on the opacity and not on the frame?

The "position" part works well in actionForKey: when implicitly setting the position of the layer.

Cheers,
Joachim

P.S. I'm afraid this is not my last CA related question on this list. I hope you'll have more patience with me...
_______________________________________________


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:
    • [SOLVED] Re: CAAnimationGroup doesn't do all animations
      • From: Joachim <email@hidden>
  • Prev by Date: Sizing window question
  • Next by Date: Re: why are there zero examples in the cocoa docs?!
  • Previous by thread: Re: Sizing window question
  • Next by thread: [SOLVED] Re: CAAnimationGroup doesn't do all animations
  • Index(es):
    • Date
    • Thread