如何实现这种文字切换动画?每个角色都有不透明度、位置和模糊的更改。不透明度和位置正在起作用。我找不到模糊的方法。就像这样:
func runTextAnimationPostion_Show() -> Void {
isShowing = true
for (idx,item) in textLayers.enumerated() {
item.position = textLayerPostions[idx];
item.removeAllAnimations();
item.opacity = 0.0
}
for (index,textLayer) in textLayers.enumerated() {
let animation2 = CABasicAnimation(keyPath: "opacity");
animation2.fromValue = 0.0
animation2.toValue = 1.0;
let duration2 = Double(animationTime / Double(textLayers.count));
animation2.duration = duration2*3.0;
animation2.repeatCount = 1;
animation2.beginTime = CACurrentMediaTime() + Double(index) * duration2;
animation2.fillMode = .forwards;
animation2.isRemovedOnCompletion = false;
textLayer.add(animation2, forKey: "\(index)+o");
let position = textLayerPostions[index];
let point = CGPoint(x: textLayer.position.x, y: position.y - 10);
textLayer.position = point;
let animation = CABasicAnimation(keyPath: "position");
animation.fromValue = point
animation.toValue = position;
let duration = Double(animationTime / Double(textLayers.count));
animation.duration = duration*3.0;
animation.repeatCount = 1;
animation.beginTime = CACurrentMediaTime() + Double(index) * duration;
animation.fillMode = .forwards;
animation.isRemovedOnCompletion = false;
textLayer.add(animation, forKey: "\(index)");
}
}
1条答案
按热度按时间polhcujo1#
在Mac OS上,您可以在图层上安装Core Image滤镜,它们将“实时”应用于图层。然后,可以构建一个核心动画来减小模糊半径。这在iOS上不起作用。
我认为你最好的办法是创建所有10个数字的模糊版本,然后动画一个数字的非模糊版本与模糊版本的顶部。在动画过程中,将模糊版本的Alpha减小为0。这将产生使图像看起来清晰的效果。
(For只有10个数字,我可能会创建模糊的版本,并将其保存为图像。或者,您可以编写代码,将任何视图的内容呈现到屏幕外呈现器中,将其捕获到UIImage,然后对图像应用Core Image Gaussian模糊过滤器。然后你把模糊的图像安装在非模糊图像的上面。