嗨,我要从多个图像创建关键帧动画。我的问题是我希望动画立即从一个图像更改为下一个图像,而不是淡入淡出。
CALayer *animLayer = [CALayer layer];
animLayer.bounds = CGRectMake(0, 0, width, height);
animLayer.position = CGPointMake(0, 0);
CAKeyframeAnimation *customFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
NSArray *sizeValues = [NSArray arrayWithObjects:(id)image1, (id)image2, nil];
NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], [NSNumber numberWithFloat:0.5f], nil];
NSArray *timingFunctions = [NSArray arrayWithObjects: [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault], nil];
[customFrameAnimation setValues:sizeValues];
[customFrameAnimation setKeyTimes:times];
customFrameAnimation.duration=5.0;
customFrameAnimation.beginTime = 1e-100;
customFrameAnimation.fillMode = kCAFillModeRemoved;
customFrameAnimation.timingFunctions = timingFunctions;
customFrameAnimation.removedOnCompletion = YES;
[animLayer addAnimation:customFrameAnimation forKey:nil];
提前致谢。
最佳答案
您的动画将需要将其CalculationMode设置为kCAAnimationDiscrete。
看一看documentation on keyTimes,它描述了如何使用calculationMode:
然后,您可以阅读计算模式的说明:
换句话说,离散计算模式使动画跳到每个关键帧,而不是为其动画/过渡。
此致。
关于core-animation - CAKeyframeAnimation,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4024685/