• 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
Re: CALayer/CAAnimation doesn't animate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CALayer/CAAnimation doesn't animate


  • Subject: Re: CALayer/CAAnimation doesn't animate
  • From: Bill Dudney <email@hidden>
  • Date: Mon, 14 Jan 2008 16:07:34 -0700

Hi Joachim,

You should not be manipulating the layer that the view creates for its self as a general rule.

I.e. if you want to manipulate the layer (as you do in this code) make the view a 'layer hosting view' instead of a 'layer backed view'. The apple docs on this subject are pretty good (if you search for either of the quoted terms you should get to the article, if not please ping me again and I'll track it down).

On the more practical side of making this work...

If you call [self setLayer:[CALayer layer]] right before you call [self setWantsLayer:YES] you should start to see behavior that more closely matches what you want/expect.

HTH,

-bd-
http://bill.dudney.net/roller/objc

On Jan 14, 2008, at 3:37 PM, Joachim wrote:

I have spent hours on this - I now throw in the towel...

I have a view that will contain several layers I want to animate. There are no subviews in my view, and I'd like to keep it that way.

I have made this simple example to illustrate the problem. It's a method of the view that is supposed to add a layer and animate it:

- (void)animateNewLayer
{
   // Create layer
   CALayer *layer = [CALayer layer];

   // Configure layer
   layer.frame = CGRectMake (0, 0, 24, 24);
   layer.contents = myCGImageRef; // Created earlier in this method
   CGImageRelease (myCGImageRef);

   // Add the layer to our view's root layer
   self.wantsLayer = YES;
   [self.layer addSublayer:layer];

// Create animation
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"frameOrigin"];


// Configure animation
anim.fromValue = [NSValue valueWithPoint:NSMakePoint (0, 0)];
anim.toValue = [NSValue valueWithPoint:NSMakePoint (100, 100)];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.duration = 2.0;
anim.delegate = self;


   // Add animation to layer; also triggers the animation
   [layer addAnimation:anim forKey:@"frameOrigin"];
}

There are several problems with this code:

1) When the code runs, the layer appears containing the loaded image at (0, 0) as expected, but it doesn't move
2) If I change the keyPath to either @"opacity" or @"borderWidth", the layer does animate, but as soon as it's done animating, the layer goes back to its original appearance, and the animation doesn't take the 2 secs to complete - only a fraction
3) The delegate method, animationDidStart:, is only called in (2), not in (1), and animationDidStop: is never called in any of the scenarios


I'm totally stuck in this. Any help is hugely appreciated. I think I'm doing what's suggested in the examples in Core Animation Programming Guide, but obviously not.

Am I handling the layer hierarchy correctly? For example, can I use the view's backing layer as the root of the layer hierarchy?

Thaks in advance,
Joachim
_______________________________________________

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

_______________________________________________

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: CALayer/CAAnimation doesn't animate
      • From: Scott Anguish <email@hidden>
References: 
 >CALayer/CAAnimation doesn't animate (From: Joachim <email@hidden>)

  • Prev by Date: Re: Move window by dragging button
  • Next by Date: [SOLVED] Re: Disabling NSTableView's behavior of turning black text white
  • Previous by thread: CALayer/CAAnimation doesn't animate
  • Next by thread: Re: CALayer/CAAnimation doesn't animate
  • Index(es):
    • Date
    • Thread