首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >iOS 7.1幻灯片可解锁文本动画

iOS 7.1幻灯片可解锁文本动画
EN

Stack Overflow用户
提问于 2014-03-12 04:58:46
回答 7查看 8.9K关注 0票数 16

我不确定以前是否有人问过这个问题,但我很难找到它。也许我没有使用正确的搜索词,所以如果答案已经存在,如果有人能给我指出正确的方向,我将不胜感激!

我刚刚注意到,随着iOS 7.1的更新,锁屏上“滑动解锁”文本上的微光动画发生了变化。聚光灯现在有一个椭圆形/菱形形状,它级联在字母上,而不出现在它后面的视图中。

在过去,我通过按顺序更改单个字母的颜色来复制这种类型的功能,但为此,动画将穿过字母的中间。而不影响背景。

我怎样才能复制它?

EN

回答 7

Stack Overflow用户

发布于 2014-04-24 18:27:18

您可以为标签文本设置动画,并为其使用自定义滑块,希望它能对您有所帮助:

代码语言:javascript
复制
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;
票数 8
EN

Stack Overflow用户

发布于 2014-03-12 06:21:44

您应该能够使用CALayer的mask属性来创建另一个层内容的裁剪。

设置蒙版以包含您的文本(也许CATextLayer可以在这里工作)。这就是Shimmer所说的它使用的。

票数 4
EN

Stack Overflow用户

发布于 2014-03-13 01:26:37

将您的标签的前景颜色设置为使用启动的UIColor

+colorWithPatternImage

-initWithPatternImage

使用动画图像并将标签的背景色设置为透明。我没有试过,但我不明白为什么它不能工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22336505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档