这些动画通常是如何在Swift/iOS中完成的-参见图
为了创建与下图所示类似的动画,我需要学习什么 是否有人能列出所有涉及的技术,以及如何实现这一点的快速过程这些动画通常是如何在Swift/iOS中完成的-参见图,ios,swift,core-graphics,core-animation,Ios,Swift,Core Graphics,Core Animation,为了创建与下图所示类似的动画,我需要学习什么 是否有人能列出所有涉及的技术,以及如何实现这一点的快速过程 对于第一个动画,您可以使用CAShapeLayer和CABasic动画,并设置关键点路径的动画strokeEnd 我构建的完全相同,您可以查看此链接,下载并查看选项填充圆动画 编辑- 这里的基本思想是使用bezeir路径绘制圆,并使用keyPath strokeEnd使用Cabasicanization设置shapeLayer的动画 override func drawRect(rect:
对于第一个动画,您可以使用CAShapeLayer和CABasic动画,并设置关键点路径的动画strokeEnd 我构建的完全相同,您可以查看此链接,下载并查看选项填充圆动画 编辑- 这里的基本思想是使用bezeir路径绘制圆,并使用keyPath strokeEnd使用Cabasicanization设置shapeLayer的动画
override func drawRect(rect: CGRect) {
self.drawBezierWithStrokeColor(circleColor.CGColor,
startAngle: 0,
endAngle: 360,
animated: false)
self.drawBezierWithStrokeColor(self.fillColor.CGColor,
startAngle: 0,
endAngle: (((2*CGFloat(M_PI))/100) * CGFloat(percentage)),
animated: true)
}
//helper methods.
private func drawBezierWithStrokeColor(color:CGColor, startAngle:CGFloat, endAngle:CGFloat, animated:Bool) {
let bezier:CAShapeLayer = CAShapeLayer()
bezier.path = bezierPathWithStartAngle(startAngle, endAngle: endAngle).CGPath
bezier.strokeColor = color
bezier.fillColor = UIColor.clearColor().CGColor
bezier.lineWidth = bounds.width * 0.18
self.layer.addSublayer(bezier)
if (animated) {
let animatedStrokeEnd:CABasicAnimation = CABasicAnimation(keyPath: "strokeEnd");
animatedStrokeEnd.duration = (2.0/100)*Double(percentage);
animatedStrokeEnd.fromValue = NSNumber(float: 0.0);
animatedStrokeEnd.toValue = NSNumber(float: 1.0);
animatedStrokeEnd.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
bezier.addAnimation(animatedStrokeEnd, forKey: "strokeEndAnimation");
}
}
private func bezierPathWithStartAngle(startAngle:CGFloat, endAngle:CGFloat) -> UIBezierPath {
let center = CGPoint(x:bounds.width/2, y: bounds.height/2)
let radius = max(bounds.width, bounds.height)
let arcWidth = bounds.width * 0.25
let path = UIBezierPath(arcCenter : center,
radius : radius/2 - arcWidth/2,
startAngle : startAngle,
endAngle : endAngle ,
clockwise : true)
return path
}
对于第一个动画,您可以使用CAShapeLayer和CABasic动画,并为关键点路径设置动画 我构建的完全相同,您可以查看此链接,下载并查看选项填充圆动画 编辑- 这里的基本思想是使用bezeir路径绘制圆,并使用keyPath strokeEnd使用Cabasicanization设置shapeLayer的动画
override func drawRect(rect: CGRect) {
self.drawBezierWithStrokeColor(circleColor.CGColor,
startAngle: 0,
endAngle: 360,
animated: false)
self.drawBezierWithStrokeColor(self.fillColor.CGColor,
startAngle: 0,
endAngle: (((2*CGFloat(M_PI))/100) * CGFloat(percentage)),
animated: true)
}
//helper methods.
private func drawBezierWithStrokeColor(color:CGColor, startAngle:CGFloat, endAngle:CGFloat, animated:Bool) {
let bezier:CAShapeLayer = CAShapeLayer()
bezier.path = bezierPathWithStartAngle(startAngle, endAngle: endAngle).CGPath
bezier.strokeColor = color
bezier.fillColor = UIColor.clearColor().CGColor
bezier.lineWidth = bounds.width * 0.18
self.layer.addSublayer(bezier)
if (animated) {
let animatedStrokeEnd:CABasicAnimation = CABasicAnimation(keyPath: "strokeEnd");
animatedStrokeEnd.duration = (2.0/100)*Double(percentage);
animatedStrokeEnd.fromValue = NSNumber(float: 0.0);
animatedStrokeEnd.toValue = NSNumber(float: 1.0);
animatedStrokeEnd.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
bezier.addAnimation(animatedStrokeEnd, forKey: "strokeEndAnimation");
}
}
private func bezierPathWithStartAngle(startAngle:CGFloat, endAngle:CGFloat) -> UIBezierPath {
let center = CGPoint(x:bounds.width/2, y: bounds.height/2)
let radius = max(bounds.width, bounds.height)
let arcWidth = bounds.width * 0.25
let path = UIBezierPath(arcCenter : center,
radius : radius/2 - arcWidth/2,
startAngle : startAngle,
endAngle : endAngle ,
clockwise : true)
return path
}
如果您正在寻找现成的解决方案,请使用类似的方法。但是,如果您想自己做这件事,您可能会使用
CAShapeLayer
和CAAnimation
子类。并且是寻找预制组件的好地方。非常感谢。我不知道可可豆的事@ishaq的想法是对的。如果你的目标是快速完成,我建议你选择Cocoa控制路线。如果你对CoCoapod还没有掌握最新的技术,Ray Wenderlich有一个很好的教程,展示了如何实现CoCoapod。很酷,谢谢。我将查看教程表单Ray Wenderlich。如果您正在寻找现成的解决方案,请使用类似的方法。但是,如果您想自己做这件事,您可能会使用CAShapeLayer
和CAAnimation
子类。并且是寻找预制组件的好地方。非常感谢。我不知道可可豆的事@ishaq的想法是对的。如果你的目标是快速完成,我建议你选择Cocoa控制路线。如果你对CoCoapod还没有掌握最新的技术,Ray Wenderlich有一个很好的教程,展示了如何实现CoCoapod。很酷,谢谢。我将查看教程表格Ray Wenderlich。非常感谢您的帮助。@Teepeemm我将编辑答案并添加必要的内容details@Teepeemm-添加代码非常感谢您的帮助。@Teepeemm我将编辑答案并添加必要的内容details@Teepeemm-新增代码