我在使用 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放在它的结束位置。
如何解决此显示故障?