通过Core Text 结合 Bezier 曲线和 CAShapeLayer 可以做出绘画文字的动画。如下代码:
CGMutablePathRef letters = CGPathCreateMutable(); //创建path
CTFontRef 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); //创建line
CFArrayRef runArray = CTLineGetGlyphRuns(line); //根据line获得一个数组
// 获得每一个 run
for (CFIndex runIndex = 0; runIndex < CFArrayGetCount(runArray); runIndex++)
{
// 获得 run 的字体
CTRunRef run = (CTRunRef)CFArrayGetValueAtI