我有这个问题与CAKeyframeAnimation。在动画UIView的图层之后,我想把UIView定位到我要动画的位置,这样用户就可以继续使用这个UIView上的按钮。
我正在使用这个代码:
// Open animation
CAKeyframeAnimation *openAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
openAnimation.fillMode = kCAFillModeForwards;
openAnimation.duration = .55;
openAnimation.delegate = self;
openAnimation.removedOnCompletion = NO;
openAnimation.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:58.0],
[NSNumber numberWithFloat:48.0], nil];
openAnimation.keyTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.62],
[NSNumber numberWithFloat:1.0], nil];
openAnimation.timingFunctions = [NSArray arrayWithObjects:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil];
[locationView.layer addAnimation:openAnimation forKey:@"OPEN_ANIMATION"];
委托方法:
- (void)animationDidStop:(CAKeyframeAnimation *)anim finished:(BOOL)flag
{
locationView.y = -10.0;
}
这实际上是有效的,但在最后我有这个显示故障,动画被删除(UIView层跳转回原始位置)并立即调用委托方法,这使得它跳转到结束位置。
我觉得最后的过程是这样的:动画完成,渲染动画的最后一帧,跳回原来的位置,渲染这一帧,调用委托方法,并把uiview放在它的结束位置。
如何修复这个显示故障?
我会在添加动画到图层之前尝试设置结束位置。假设你要改变animationDidStop
函数中的position
我要改变这些线
// Set end position for layer
CAKeyframeAnimation *openAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position.y"];
openAnimation.fillMode = kCAFillModeBackwards;
//openAnimation.removedOnCompletion = NO;
// The rest of your code
他们的键值在这里很重要,因为你必须设置与键值相同的图层属性(在本例中为position
)。否则,填充模式将无法正常工作。