• 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: Why does a custom CALayer property work differently from a standard one?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why does a custom CALayer property work differently from a standard one?


  • Subject: Re: Why does a custom CALayer property work differently from a standard one?
  • From: Corbin Dunn <email@hidden>
  • Date: Thu, 25 Oct 2012 14:56:12 -0700

On Oct 25, 2012, at 4:38 AM, Roland King <email@hidden> wrote:

> Ive been struggling with this for a couple of days now.
>
> I have a custom CALayer with a custom property, percentage. It's @dynamic and set up to cause a redraw.
>
> +(BOOL)needsDisplayForKey:(NSString *)key
> {
> 	return [ @"percentage" isEqualToString:key ];
> }
>
> I return CABasicAnimations for percentage and for position with the code at the bottom in actionForKey:. The position one just makes the position change really slowly.
>
> For position all I have to do is make a CABasicAnimation, set the duration and nothing else and return it, the position animates smoothly from where it was to where it's going.
>
> If I do the same for 'percentage', just return a CABasicAnimation with the duration set, it doesn't animate, it just goes instantly to the final value. For this one I have to explicitly set the 'fromValue' to the current value in the presentation layer, leaving it nil just doesn't do the job. It finds the 'toValue' itself, but I have to tell it where it's coming from.
>
> Why do they work differently? This prevents me from using addAnimation:forKey: for 'percentage' because each one is different, depending what the current value of percentage is.
>
>
> -(id<CAAction>)actionForKey:(NSString *)event
> {
>
> 	if( [ event isEqualToString:@"position" ] )
> 	{
> 		CABasicAnimation *animation = [ CABasicAnimation animationWithKeyPath:@"position" ];
> 		animation.duration = 7.f;
> 		return animation;

Technically, the above code is incorrect. You have to set one of the values, per the header comment.


/* The objects defining the property values being interpolated between.
 * All are optional, and no more than two should be non-nil. The object
 * type should match the type of the property being animated (using the
 * standard rules described in CALayer.h). The supported modes of
 * animation are:
 *
 * - both `fromValue' and `toValue' non-nil. Interpolates between
 * `fromValue' and `toValue'.
 *
 * - `fromValue' and `byValue' non-nil. Interpolates between
 * `fromValue' and `fromValue' plus `byValue'.
 *
 * - `byValue' and `toValue' non-nil. Interpolates between `toValue'
 * minus `byValue' and `toValue'.
 *
 * - `fromValue' non-nil. Interpolates between `fromValue' and the
 * current presentation value of the property.
 *
 * - `toValue' non-nil. Interpolates between the layer's current value
 * of the property in the render tree and `toValue'.
 *
 * - `byValue' non-nil. Interpolates between the layer's current value
 * of the property in the render tree and that plus `byValue'. */


corbin


> 	}

>
> 	if( [ event isEqualToString:@"percentage" ] )
> 	{
> 		CABasicAnimation *animation = [ CABasicAnimation animationWithKeyPath:@"percentage" ];
> 		animation.duration = 2.f;
> 		animation.fromValue = [ self.presentationLayer valueForKey:event ];
> 		return animation;
> 	}
>
> 	return [ super actionForKey:event ];;
> }
> _______________________________________________
>
> 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: Why does a custom CALayer property work differently from a standard one?
      • From: Roland King <email@hidden>
References: 
 >Why does a custom CALayer property work differently from a standard one? (From: Roland King <email@hidden>)

  • Prev by Date: Re: Object not being drawn in Cmd + N window. Why?
  • Next by Date: Re: Binding InfoPanel to currentDocument
  • Previous by thread: Why does a custom CALayer property work differently from a standard one?
  • Next by thread: Re: Why does a custom CALayer property work differently from a standard one?
  • Index(es):
    • Date
    • Thread