开发者

Duration set up with CATransform3DMakeTranslation

开发者 https://www.devze.com 2023-04-07 05:11 出处:网络
my first question on stack overflow :) I want to make a y axis translation on a CALayer. I got a big background : 320x4000px.

my first question on stack overflow :)

I want to make a y axis translation on a CALayer. I got a big background : 320x4000px. The translation is working with the following code :

NSNumber *deplacement = [NSNumber numberWithFloat:([app.session.progression floatValue] * HAUTEUR_FOND) /100];

self.backgroundLayer.transform = CATransform3DMakeTranslation(0, -[deplacement floatValue], 0);

But with this code, it's impossible to set up a duration ...

I tried with that :

CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"];
transformAnimation.duration = 5.0f;
transformAnimatio开发者_如何学JAVAn.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeTranslation(0, -[deplacement floatValue], 0)];
[self.backgroundLayer addAnimation:transformAnimation forKey:@"position.y"];

but it does not work ...

Thanks for help :)


Ok, here is the answer, maybe it will help someone :)

NSNumber *deplacement = [NSNumber numberWithFloat:([app.session.progression floatValue] * HAUTEUR_FOND) /100];
DebugLog(@"deplacement : %@", deplacement);

if(!backgroundPositionMemo) backgroundPositionMemo = 0;

CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
transformAnimation.duration = 1.0f;
transformAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeTranslation(0, -backgroundPositionMemo, 0)];
transformAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeTranslation(0, -[deplacement floatValue], 0)];
transformAnimation.removedOnCompletion = NO;
transformAnimation.fillMode = kCAFillModeForwards;
[self.backgroundLayer addAnimation:transformAnimation forKey:@"transform"];

backgroundPositionMemo = [deplacement floatValue];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号