Re: CABasicAnimation does not animate bounds.origin of a layer

2019-09-14 Thread Steve Christensen via Cocoa-dev
First guess would be not to explicitly set -anchorPosition. It defaults to 
(0.5, 0.5), which refers to the middle of the bounds, and transforms (like 
scaling) are applied relative to that position.


> On Sep 14, 2019, at 6:25 AM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> Maybe, I haven't understood how the animation of the bounds property works,
> or the bounds property of a CALayer itself ,
> or I am making a stupid mistake.
> 
> Here is my code:
> 
>CALayer * imgLayer = [CALayer layer];
>imgLayer.contents= (__bridge id) imageRef;
>imgLayer.delegate= nil;
>imgLayer.opacity = 1.0;  
>imgLayer.anchorPoint  = CGPointMake( 0.0, 0.0 );
>imgLayer.zPosition   = -1.0;   
> 
>CABasicAnimation * anim = [CABasicAnimation animationWithKeyPath: 
> @"bounds"];
>anim.timingFunction = [CAMediaTimingFunction functionWithName: 
> kCAMediaTimingFunctionLinear];
>anim.duration  = 5;// sec
>anim.autoreverses  = YES;
>anim.repeatCount  = 100;  // = 
> forever
> 
>NSRect from_rect = NSMakeRect( 100.0, 100.0, 200.0, 200.0 );
>anim.fromValue= [NSValue valueWithRect: from_rect ];
>NSRect to_rect = NSMakeRect( 200.0, 200.0, 300.0, 300.0 );
>anim.toValue = [NSValue valueWithRect: to_rect ];
> 
>[imgLayer addAnimation: anim forKey: @"myBoundsAnim"];
> 
> 
> What I am seeing is that the image gets scaled (from  200 to 300 
> width/height) which is fine,
> but it always sits in the lower left corner of the screen (I am working under 
> macOS).
> 
> I want the lower left corner of the image to be animated , too.
> (Eventually, the animation will be a bit more complex, but for now I am just 
> trying to understand this.)
> 
> What am I missing? or going wrong?
> 
> I guess I could achieve the effect by animating the position property of the 
> layer,
> but I'd rather prefer to understand what is going on.
> I have also re-read the "Core Animation Basics" , but it doesn't explain the 
> meaning of bounds.origin.
> In the drawings, it's always (0,0).
> 
> Thanks a lot in advance for any insights.
> 
> Best regards, Gabriel

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


CABasicAnimation does not animate bounds.origin of a layer

2019-09-14 Thread Gabriel Zachmann via Cocoa-dev
Maybe, I haven't understood how the animation of the bounds property works,
or the bounds property of a CALayer itself ,
or I am making a stupid mistake.

Here is my code:

CALayer * imgLayer = [CALayer layer];
imgLayer.contents= (__bridge id) imageRef;
imgLayer.delegate= nil;
imgLayer.opacity = 1.0;  
imgLayer.anchorPoint  = CGPointMake( 0.0, 0.0 );
imgLayer.zPosition   = -1.0;   

CABasicAnimation * anim = [CABasicAnimation animationWithKeyPath: 
@"bounds"];
anim.timingFunction = [CAMediaTimingFunction functionWithName: 
kCAMediaTimingFunctionLinear];
anim.duration  = 5; // sec
anim.autoreverses  = YES;
anim.repeatCount  = 100;  // = 
forever

NSRect from_rect = NSMakeRect( 100.0, 100.0, 200.0, 200.0 );
anim.fromValue= [NSValue valueWithRect: from_rect ];
NSRect to_rect = NSMakeRect( 200.0, 200.0, 300.0, 300.0 );
anim.toValue = [NSValue valueWithRect: to_rect ];

[imgLayer addAnimation: anim forKey: @"myBoundsAnim"];


What I am seeing is that the image gets scaled (from  200 to 300 width/height) 
which is fine,
but it always sits in the lower left corner of the screen (I am working under 
macOS).

I want the lower left corner of the image to be animated , too.
(Eventually, the animation will be a bit more complex, but for now I am just 
trying to understand this.)

What am I missing? or going wrong?

I guess I could achieve the effect by animating the position property of the 
layer,
but I'd rather prefer to understand what is going on.
I have also re-read the "Core Animation Basics" , but it doesn't explain the 
meaning of bounds.origin.
In the drawings, it's always (0,0).

Thanks a lot in advance for any insights.

Best regards, Gabriel








smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com