【发布时间】:2018-08-11 17:43:39
【问题描述】:
我想实现这种类型的动画。请查看此网址
https://www.dropbox.com/s/gz9vfy5refsh7a5/Screen.mov?dl=0
我正在添加我在项目中使用的代码,在该项目中我使用 Core Graphics 来渲染带有动画的文本,但我无法为上述链接中显示的文本设置动画
这是我用来在屏幕上呈现文本的代码
let context = UIGraphicsGetCurrentContext()!
context.saveGState()
context.setAlpha(noLightText)
let nOLIGHTRect = CGRect(x: 145.66, y: 590, width: 449.38, height: 125)
let nOLIGHTStyle = NSMutableParagraphStyle()
nOLIGHTStyle.alignment = .center
let nOLIGHTFontAttributes = [
.font: UIFont(name: "Futura-CondensedExtraBold", size: 96)!,
.foregroundColor: nOLIGHTColor,
.paragraphStyle: nOLIGHTStyle,
] as [NSAttributedStringKey: Any]
"NO LIGHT".draw(in: nOLIGHTRect, withAttributes: nOLIGHTFontAttributes)
context.restoreGState()
//// LOW LIGHT Drawing
context.saveGState()
context.setAlpha(_0)
let lOWLIGHTRect = CGRect(x: 145.94, y: 590, width: 449.38, height: 125)
let lOWLIGHTStyle = NSMutableParagraphStyle()
lOWLIGHTStyle.alignment = .left
let lOWLIGHTFontAttributes = [
.font: UIFont(name: "Futura-CondensedExtraBold", size: 96)!,
.foregroundColor: lOWLIGHTColor,
.paragraphStyle: lOWLIGHTStyle,
] as [NSAttributedStringKey: Any]
"LOW LIGHT".draw(in: lOWLIGHTRect, withAttributes: lOWLIGHTFontAttributes)
context.restoreGState()
//// MID LIGHT Drawing
context.saveGState()
context.setAlpha(mediumLightText)
let mIDLIGHTRect = CGRect(x: 145.77, y: 590, width: 449.38, height: 125)
let mIDLIGHTStyle = NSMutableParagraphStyle()
mIDLIGHTStyle.alignment = .left
let mIDLIGHTFontAttributes = [
.font: UIFont(name: "Futura-CondensedExtraBold", size: 96)!,
.foregroundColor: mIDLIGHTColor,
.paragraphStyle: mIDLIGHTStyle,
] as [NSAttributedStringKey: Any]
"MID LIGHT".draw(in: mIDLIGHTRect, withAttributes: mIDLIGHTFontAttributes)
context.restoreGState()
【问题讨论】:
-
如果有人能推荐一个关于 CAShapeLayers 和一般动画的基本入门,我将不胜感激
-
将该属性字符串转换为 CGPath 或 BezierPath。然后将该路径设置为 CAShapeLayer 并设置描边。使用 CABasicAnimation 为笔画设置动画,瞧..
-
感谢您的回复。您能否提供任何需要动画的代码
标签: ios objective-c swift3 core-graphics swift4