Why does a custom CALayer property work differently from a standard one?
Why does a custom CALayer property work differently from a standard one?
- Subject: Why does a custom CALayer property work differently from a standard one?
- From: Roland King <email@hidden>
- Date: Thu, 25 Oct 2012 19:38:17 +0800
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;
}
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