关于堆栈溢出的第一个问题:)
我想在CALayer上进行y轴平移。我有一个很大的背景:320x4000px。 翻译使用以下代码:
NSNumber *deplacement = [NSNumber numberWithFloat:([app.session.progression floatValue] * HAUTEUR_FOND) /100];
self.backgroundLayer.transform = CATransform3DMakeTranslation(0, -[deplacement floatValue], 0);
但是使用此代码,无法设置持续时间......
我试过了:
CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"];
transformAnimation.duration = 5.0f;
transformAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeTranslation(0, -[deplacement floatValue], 0)];
[self.backgroundLayer addAnimation:transformAnimation forKey:@"position.y"];
但它不起作用......
感谢您的帮助:)
答案 0 :(得分:2)
好的,这是答案,也许它会帮助某人:)
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];