2

在已经翻译过一次之后,我只是想将图层翻译回其原始位置。我总是可以将我翻译的图层位置存储在一个属性中,但似乎有更好的方法。我正在做这样的事情来翻译我的图层:

CABasicAnimation *slide = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
slide.byValue = [NSNumber numberWithFloat:translationValue];
slide.duration = duration;
slide.removedOnCompletion = NO;
slide.fillMode = kCAFillModeForwards;
slide.autoreverses = NO;

[layer addAnimation:slide forKey:KEYPATH_POSITION];

我试图做类似下面的事情,但这没有动画,它只是回到原来的位置。

CABasicAnimation *slide = [CABasicAnimation animationWithKeyPath:@"position"];
slide.toValue = [layer valueForKey:@"position"];
slide.duration = duration;
slide.removedOnCompletion = NO;
slide.fillMode = kCAFillModeForwards;
slide.autoreverses = NO;

[layer addAnimation:slide forKey:KEYPATH_POSITION];
4

0 回答 0