【发布时间】:2015-12-25 18:08:57
【问题描述】:
我目前正在使用此代码来动画角色的绘制:
var path = UIBezierPath()
var unichars = [UniChar]("J".utf16)
var glyphs = [CGGlyph](count: unichars.count, repeatedValue: 0)
let gotGlyphs = CTFontGetGlyphsForCharacters(font, &unichars, &glyphs, unichars.count)
if gotGlyphs {
let cgpath = CTFontCreatePathForGlyph(font, glyphs[0], nil)
path = UIBezierPath(CGPath: cgpath!)
}
从一个字符(在本例中为“J”)创建一个贝塞尔路径。 Get path to trace out a character in an iOS UIFont
然后我创建一个CAShapeLayer() 并为其添加动画。
let layer = CAShapeLayer()
layer.position = //CGPoint
layer.bounds = //CGRect()
view.layer.addSublayer(layer)
layer.path = path.CGPath
layer.lineWidth = 5.0
layer.strokeColor = UIColor.blackColor().CGColor
layer.fillColor = UIColor.clearColor().CGColor
layer.geometryFlipped = true
layer.strokeStart = 0.0
layer.strokeEnd = 1.0
let anim = CABasicAnimation(keyPath: "strokeEnd")
anim.duration = 8.0
anim.fromValue = 0.0
anim.toValue = 1.0
layer.addAnimation(anim, forKey: nil)
结果是我选择的角色动画正确。但是,当我使用.appendPath() 向path 添加另一个路径时,附加的路径会如您所料那样直接添加到原始路径中。如果我想绘制一个所有字符都有适当间距等的字母,我该怎么办?
感谢您的宝贵时间。
【问题讨论】:
标签: ios swift uikit core-animation cgpath