我只想在将图层翻译一次后将图层翻译回原始位置。我总是可以将我翻译的图层位置存储在属性中,但似乎有更好的方法。我正在做这样的事情来翻译我的图层:
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];