效果

代码

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
@interface ViewController ()
{CATextLayer *textLayer;CAGradientLayer *gradientLayer;UIView* bgView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, self.view.frame.size.height - 40, self.view.frame.size.width, 40);
[btn setTitle:@"开始动画" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.view addSubview:btn];bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 40, self.view.frame.size.width, self.view.frame.size.width)];
bgView.backgroundColor = [UIColor brownColor];
[self.view addSubview:bgView];textLayer = [CATextLayer layer];
textLayer.frame = CGRectMake((bgView.frame.size.width - 200)/2, (bgView.frame.size.width - 200)/2, 200, 200);
textLayer.foregroundColor = [UIColor blackColor].CGColor;
textLayer.alignmentMode =kCAAlignmentJustified;
textLayer.wrapped =YES;
UIFont *font = [UIFont systemFontOfSize:30];
CFStringRef fontName = (__bridge CFStringRef)font.fontName;
CGFontRef fontRef =CGFontCreateWithFontName(fontName);
textLayer.font = fontRef;
textLayer.fontSize = font.pointSize;
CGFontRelease(fontRef);
NSString *text =@"习惯不曾习惯的习惯会习惯 舍得不曾舍得的舍得会舍得";
textLayer.string = text;
textLayer.contentsScale = [UIScreen mainScreen].scale;
[bgView.layer addSublayer:textLayer];
//创建背景图层
gradientLayer =  [CAGradientLayer layer];
[gradientLayer setColors:[NSArray arrayWithObjects:(id)[UIColorFromRGB(0x000000) CGColor],(id)[UIColorFromRGB(0xFFD700) CGColor],(id)[UIColorFromRGB(0x000000) CGColor],(id)[UIColorFromRGB(0xFFD700) CGColor],(id)[UIColorFromRGB(0x000000) CGColor],(id)[UIColorFromRGB(0xFFD700) CGColor],(id)[UIColorFromRGB(0x000000) CGColor],(id)[UIColorFromRGB(0xFFD700) CGColor],(id)[UIColorFromRGB(0x000000) CGColor],(id)[UIColorFromRGB(0xFFD700) CGColor],(id)[UIColorFromRGB(0x000000) CGColor],(id)[[UIColor clearColor] CGColor],nil]];
gradientLayer.frame = bgView.bounds;
[gradientLayer setLocations:[NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],[NSNumber numberWithFloat:0.1],[NSNumber numberWithFloat:0.2],[NSNumber numberWithFloat:0.3],[NSNumber numberWithFloat:0.4],[NSNumber numberWithFloat:0.5],[NSNumber numberWithFloat:0.6],[NSNumber numberWithFloat:0.7],[NSNumber numberWithFloat:0.8],[NSNumber numberWithFloat:0.9],[NSNumber numberWithFloat:1.0],nil]];[gradientLayer setStartPoint:CGPointMake(0, 0)];
[gradientLayer setEndPoint:CGPointMake(1, 1)];
[gradientLayer setMask:textLayer]; //用progressLayer来截取渐变层
[bgView.layer addSublayer:gradientLayer];
}
- (void)clickBtn{
//动画
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
CGPoint fromPoint = textLayer.position;
CGPoint toPoint = CGPointMake(fromPoint.x + (bgView.frame.size.width - 200)/2, fromPoint.y);
animation.duration = 1;
animation.fromValue = http://blog.csdn.net/xiaoxiaobukuang/article/details/[NSValue valueWithCGPoint:fromPoint];
animation.toValue = [NSValue valueWithCGPoint:toPoint];
animation.autoreverses = YES;
[textLayer addAnimation:animation forKey:nil];CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"position"];
CGPoint fromPoint2 = gradientLayer.position;
CGPoint toPoint2 = CGPointMake(fromPoint.x - (bgView.frame.size.width - 200)/2, fromPoint.y);
animation2.duration = 1;
animation2.fromValue = http://blog.csdn.net/xiaoxiaobukuang/article/details/[NSValue valueWithCGPoint:fromPoint2];
animation2.toValue = [NSValue valueWithCGPoint:toPoint2];
animation2.autoreverses = YES;
[gradientLayer addAnimation:animation2 forKey:nil];
}

转载于:https://www.cnblogs.com/sunyanyan/p/5360192.html

会员金闪闪动画字体 (CATextLayer + CAGradientLayer)相关推荐

  1. QML 发光呼吸动画字体

    前言 用 QML 来实现一个呼吸动画效果的字体,非常酷炫,主要使用 Glow 组件来实现,然后通过控制透明度的改变来实现想要的效果,代码非常简单. 正文 先来看看效果 源码: Item {Rectan ...

  2. android 动画字体,Android字体多样式和动画TextDrawable

     Android字体多样式和动画TextDrawable 在实际的Android开发中,很多时候,需要用TextView表现和展示view的内容和标题.标签之类.但是Android本身提供的Tex ...

  3. css3字体闪烁炫酷,css3 scale动画 字体、输入框等会闪烁,怎么解决?

    画图 @-moz-keyframes loginAnimation { from { opacity: 0; -moz-transform: scale(2); } to { opacity: 1; ...

  4. Qt QML实现阴影字体

    概述 前面写过一篇文章介绍如何使用 QML 做渐变色字体,文章在这里,还写过一篇文章是用 QML 实现发光呼吸动画字体,文章在这里.今天介绍一种关于字体的新的效果,用 QML 实现阴影效果字体. 正文 ...

  5. 六、CSS 速览 —— 平面转换、3D转换、动画

    平面转换.3D转换.动画 字体图标 iconfont 阿里图标库 从图标库引用素材 平面转换 transition: all 1s; 设置元素变换动画 transform: translate(px, ...

  6. InDesign 教程如何更改字体和字体大小?

    欢迎观看indesign教程,小编带大家学习 InDesign 的基本工具和使用技巧,了解如何更改字体和字体大小. InDesign 提供了许多格式化文档中文本的方法.在本项目中,将使用「属性」面板将 ...

  7. 思量QQ本地会员v3.8官方2013版【免费使用部分QQ会员功能】

    思量QQ本地会员(2013版) v3.8官方版 授权方式:免费软件 界面语言:简体中文 软件大小:1024KB 所属专题:网络软件 运行环境:Win2K,WinXP,Win2003,Vista,Win ...

  8. SVGA 礼物动画设计相关

    1.1 什么是SVGA SVGA 是由 YY 团队开发出来的一种跨平台的开源动画格式,同时兼容 iOS / Android / Web.SVGA 除了使用简单,性能卓越,同时让动画开发分工明确,各自专 ...

  9. 计算机动漫与游戏制作与影视,中职中专计算机动漫与游戏制作专业系列教材·动画与影视后期制作:After Effects CS4技能应用教程...

    中职中专计算机动漫与游戏制作专业系列教材·动画与影视后期制作:After Effects CS4技能应用教程 语音 编辑 锁定 讨论 上传视频 <中职中专计算机动漫与游戏制作专业系列教材·动画与 ...

最新文章

  1. 使用MLX90640自制红外热像仪(三):图像插值、图像彩色编码
  2. 机器学习算法源码全解析(三)-范数规则化之核范数与规则项参数选择
  3. HTML学习03之列表,表格,媒体元素
  4. 设计模式:中介者模式(Mediator)
  5. 创建 Image - 每天5分钟玩转 OpenStack(21)
  6. java多线程打印helloworld,Java并发编程--多线程之HelloWorld
  7. 【Cocos新手入门】cocos creator + Visual Studio 做游戏开发的基础教程
  8. Scrapy框架初探
  9. ASP.NET中后台实现页面加载中效果(数据过多时提高用户体验度)
  10. 一条来自水圈的鄙视链
  11. 洛谷 P1858 多人背包
  12. mfw 攻防世界web题 (Git泄露)
  13. java拼图游戏ai_拼图游戏和它的AI算法
  14. IGBT晶圆在新能源汽车充电桩领域的应用
  15. 几种常见窗函数及其MATLAB实现
  16. .Net iTextSharp 给Pdf添加图片水印
  17. 独角兽扎堆新加坡,Shopee、Lazada们究竟看见了怎样的未来?
  18. ThinkSystem SR650 BMC管理口配置
  19. C# CAD视图操作之缩放
  20. 2022新UI美观发卡网源码下载+功能强大且齐全

热门文章

  1. 供应商质量工程师(SQE)是做什么的?
  2. web快速入门之基础篇-html:2、基本标签之标题标签、段落标签、换行标签
  3. Azure Key Vault 简介
  4. 史上最全的FTP网址
  5. java经典问题:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高?
  6. 网狐大联盟启用AI功能
  7. DPlayer视频播放器使用方法介绍
  8. Ubuntu下点阵汉字的字模读取与显示
  9. 【DBA100人】李建明:一名普通DBA的14年技术之路与成长智慧
  10. hbuilder 上传图片 保存图片 拍照 muse ui