iOS 7.1滑动解锁文字动画

标签 ios objective-c animation ios7.1

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

我刚刚注意到,随着 iOS 7.1 更新,锁屏“滑动解锁”文本上的微光动画发生了变化。聚光灯现在具有椭圆形/菱形形状,层叠穿过字母而不会出现在其后面的 View 中。

iOS 7.1 Lock Screen Text Animation

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

我怎样才能复制这个?

最佳答案

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

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;

关于iOS 7.1滑动解锁文字动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22336505/

相关文章:

ios - 自构建预编译头以来文件已被修改

ios - iOS 14 中的可变字体

php - 如何从 Objective-C/iOS 中恢复 PHP $_SESSION 变量?

ios - 如何在 UICollectionView 中居中行?

ios - 如何同时为 UIImageView 的图像和 UIImageView 本身设置动画?

c# - 代码应在短暂延迟后执行一次

iphone - 如何从 UIbutton 选择器调用方法?

ios - 在 xcode 中集中显示弹出窗口

javascript - 平滑停止 CSS 关键帧动画

iphone - UIView动画使用90%CPU