通过Core Text 结合 Bezier 曲线和 CAShapeLayer 可以做出绘画文字的动画。如下代码:

CGMutablePathRef letters = CGPathCreateMutable();   //创建pathCTFontRef font = CTFontCreateWithName(CFSTR("Helvetica-Bold"), 100.0f, NULL);       //设置字体NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:(id)font, kCTFontAttributeName,nil];NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"" attributes:attrs];CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrString);   //创建lineCFArrayRef runArray = CTLineGetGlyphRuns(line);     //根据line获得一个数组// 获得每一个 runfor (CFIndex runIndex = 0; runIndex < CFArrayGetCount(runArray); runIndex++){// 获得 run 的字体CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, runIndex);CTFontRef runFont = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName);// 获得 run 的每一个形象字for (CFIndex runGlyphIndex = 0; runGlyphIndex < CTRunGetGlyphCount(run); runGlyphIndex++) {// 获得形象字CFRange thisGlyphRange = CFRangeMake(runGlyphIndex, 1);//获得形象字信息CGGlyph glyph;CGPoint position;CTRunGetGlyphs(run, thisGlyphRange, &glyph);CTRunGetPositions(run, thisGlyphRange, &position);// 获得形象字外线的path{CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyph, NULL);CGAffineTransform t = CGAffineTransformMakeTranslation(position.x, position.y);CGPathAddPath(letters, &t, letter);CGPathRelease(letter);}}}CFRelease(line);//根据构造出的 path 构造 bezier 对象UIBezierPath *path = [UIBezierPath bezierPath];[path moveToPoint:CGPointZero];[path appendPath:[UIBezierPath bezierPathWithCGPath:letters]];CGPathRelease(letters);CFRelease(font);//根据 bezier 创建 shapeLayer对象CAShapeLayer *pathLayer = [CAShapeLayer layer];pathLayer.frame = self.animationLayer.bounds;pathLayer.bounds = CGPathGetBoundingBox(path.CGPath);pathLayer.geometryFlipped = YES;pathLayer.path = path.CGPath;pathLayer.strokeColor = [[UIColor blackColor] CGColor];pathLayer.fillColor = nil;pathLayer.lineWidth = 3.0f;pathLayer.lineJoin = kCALineJoinBevel;[self.animationLayer addSublayer:pathLayer];self.pathLayer = pathLayer;

//开始动画

- (void) startAnimation
{[self.pathLayer removeAllAnimations];CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];pathAnimation.duration = 10.0;pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];[self.pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];}

代码来源: http://oleb.net/blog/2010/12/animating-drawing-of-cgpath-with-cashapelayer/

iOS实现绘画文字动画相关推荐

  1. iOS 文字动画,文字逐个显示

    随手记: 对于iOS文字动画,首先想到的应该是基于CoreText框架将文字每个都写出来,加上定时器给定每个字显示的时间,这是一种思维方式: #import "ViewController. ...

  2. Flash绘画与动画宝典

    [书名]Flash绘画与动画宝典(含DVD光盘1张)(全彩) [作者]宇传华 著 [ISBN]978-7-121-07516-2 [出版社]电子工业出版社 [出版日期]2009年1月 [宣传语] 绘画 ...

  3. android源代码下载AE 文字样式,有了它,不会AE也可以用手机快速做出漂亮的文字动画——Legend#Android...

    在网上常常能看到很多好看的文字动画,好玩炫酷.比如下面这些: 上面5个动图均来自微博:@AfterEffects资源库 这些动图都是用电脑上的AE(Adobe After Effects)做的,我看网 ...

  4. iOS UIButton 图片文字上下垂直布局 解决方案

    iOS UIButton 图片文字上下垂直布局 解决方案 参考文章: (1)iOS UIButton 图片文字上下垂直布局 解决方案 (2)https://www.cnblogs.com/yajunL ...

  5. VCTransitionsLibrary –自定义iOS交互式转场动画的库

    简介 VCTransitionsLibrary 提供了许多适用于入栈,出栈,模态等场景下控制器切换时的转场动画.它本身提供了一个定义好的转场动画库,你可以拖到自己工程中直接使用;也提供了许多拥有不同转 ...

  6. html给文字加动态效果,20种配合场景的CSS3鼠标滑过文字动画特效

    这是一组非常有创意的配合场景使用的CSS3鼠标滑过文字动画特效.这组鼠标滑过特效中,以20张不同的图片作为不同的场景,例如图片是一条公路,鼠标滑过这上面的文字时,就会在文字下边出现一条公路的动画效果. ...

  7. 这文字的起始位置_ae制作文字动画?ae文字动画教程

    ae文字动画技巧教程: 第1步 创建一个新的合成,转到文件并选择一个新的合成 第2步 选择[T]文本工具 第3步 输入您的文字. 第4步 根据您的需要更改文本的颜色. 第5步 借助选择工具[V]调整文 ...

  8. IOS之代理文字点击变大变小

    IOS之代理文字点击变大变小 重点是掌握代理的使用,否则也失去次此意义 #import "ViewController.h" #import "AHLJFontSizeP ...

  9. confirm修改按钮文字_踏入MG动画设计的门,才知道文字动画这么重要……

    和大多数影视后期一样,在MG动画的制作中,文字也担负着重要的角色,除了对画面信息的补充和媒介交流,也是设计师们常用来作为视觉设计的辅助元素. After Effects作为MG动画设计师主要的设计软件 ...

最新文章

  1. oracle 密码文件作用,测试 oracle 密码文件在何时起作用
  2. Hadoop 集群启动与停止
  3. rmmod: can't change directory to '3.4.39': No such file or directory 解决方法
  4. 家用电器用户行为分析与事件识别代码详解+修改后运行无误的代码
  5. Android布局中的空格以及占一个汉字宽度的空格的实现
  6. linux3.0-内核自带led驱动移植
  7. 基于 VS 2010 阐述C# 4个特性
  8. 英语c开头语言,字母c开头的英语短语
  9. shell学习笔记 (9.1)
  10. CentOS 报no acceptable C compiler found in $PATH的解决办法
  11. Mongodb db.serverStatus()所关心的几个输出值
  12. DataSetProvider的Option属性
  13. 怎么升级Android Studio版本,Android studio 2 版本升级 Android studio 3 版本注意事项
  14. 软件测试行业前景,人才稀缺
  15. 链表的实现(C语言)
  16. M1芯片,PS2022版真的来了。Photoshop 2022 for Mac中文版介绍安装教程,支持Monterey系统
  17. 上网软件 Chrome/FireFox插件-gooreplacer
  18. webService和WebApi的区别
  19. 基于flink的电商用户行为数据分析【1】| 项目整体介绍
  20. 【毕业设计】深度学习抽烟行为检测算法研究与实现 - python opencv YOLO

热门文章

  1. B模式超声成像仿真(MATLAB k-Wave仿真)
  2. 酷开与鸿蒙哪个好用,上手说说创维电视与酷开有区别没有?哪个好?老司机透漏评测...
  3. 【andriod】设备APP开发之数据就地Excel存储
  4. Unity-Live2d(模型与贴图建立联系,渲染,显示图片)
  5. ipip.net IP位置信誉信息爬取
  6. Android Data Binding 详细介绍与使用
  7. 网站前台静态页面html模板
  8. 嵌入式应用软件架构设计
  9. bilibili账号申诉中心_B站的申诉渠道究竟在哪啊
  10. Linux命令之bc命令