我不确定以前是否有人问过这个问题,但我很难找到它。也许我没有使用正确的搜索词,所以如果答案已经存在,如果有人能给我指出正确的方向,我将不胜感激!
我刚刚注意到,随着iOS 7.1的更新,锁屏上“滑动解锁”文本上的微光动画发生了变化。聚光灯现在有一个椭圆形/菱形形状,它级联在字母上,而不出现在它后面的视图中。
在过去,我通过按顺序更改单个字母的颜色来复制这种类型的功能,但为此,动画将穿过字母的中间。而不影响背景。
我怎样才能复制它?
发布于 2014-04-24 18:27:18
您可以为标签文本设置动画,并为其使用自定义滑块,希望它能对您有所帮助:
CALayer *maskLayer = [CALayer layer];
// Mask image ends with 0.15 opacity on both sides. Set the background color of the layer
// to the same value so the layer can extend the mask image.
maskLayer.backgroundColor = [[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.15f] CGColor];
maskLayer.contents = (id)[[UIImage imageNamed:@"Mask.png"] CGImage];
// Center the mask image on twice the width of the text layer, so it starts to the left
// of the text layer and moves to its right when we translate it by width.
maskLayer.contentsGravity = kCAGravityCenter;
maskLayer.frame = CGRectMake(myLabel.frame.size.width * -1, 0.0f, myLabel.frame.size.width * 2, myLabel.frame.size.height);
// Animate the mask layer's horizontal position
CABasicAnimation *maskAnim = [CABasicAnimation animationWithKeyPath:@"position.x"];
maskAnim.byValue = [NSNumber numberWithFloat:myLabel.frame.size.width];
maskAnim.repeatCount = 1e100f;
maskAnim.duration = 1.5f;
[maskLayer addAnimation:maskAnim forKey:@"slideAnim"];
myLabel.layer.mask = maskLayer;
发布于 2014-03-12 06:21:44
您应该能够使用CALayer的mask
属性来创建另一个层内容的裁剪。
设置蒙版以包含您的文本(也许CATextLayer可以在这里工作)。这就是Shimmer所说的它使用的。
发布于 2014-03-13 01:26:37
将您的标签的前景颜色设置为使用启动的UIColor
+colorWithPatternImage
或
-initWithPatternImage
使用动画图像并将标签的背景色设置为透明。我没有试过,但我不明白为什么它不能工作。
https://stackoverflow.com/questions/22336505
复制相似问题