我正在尝试使用Core Graphics绘制一个半圆并用一些颜色填充它.我想用CALayer替换颜色和图像.任何人都可以帮助如何做到这一点谢谢!
代码在这里.
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextMoveToPoint(context, 0, 500);
CGContextAddArc(context, 60, 500, 50, 90, 180, 0);
CGContextStrokePath(context);
Run Code Online (Sandbox Code Playgroud) 我是ios的新手程序员.在我的一个项目中,我需要绘制一个圆圈,其中圆圈的不同部分将填充不同的颜色.我可以绘制圆圈.但我无法确定不同的部分圆圈,并用不同的颜色填充它们.这是一个截图,以澄清我想要绘制的内容.
帮助将不胜感激.
我需要使用类似HUD的饼图动画来动画化圆形进度表的填充。我已经找到了使用Core Animation如何以纯色为路径设置动画的示例。所不同的是,我需要将其填充为图像蒙版(请参见链接),而不是纯色。
有人可以提供有关使用Core Animation或其他方法进行此操作的建议吗?
我试图动画CAShapeLayer的路径,以便我得到一个圆圈"填充"达到特定数量的效果.
问题
它"作品",而不是AS,因为我认为这可能是的,我想介绍一些宽松政策之平滑.但是因为我是单独制作每个%的动画,所以我不确定现在是否可能.所以我正在寻找可以解决这个问题的替代方案!
视觉解释
首先 - 这里是我想要实现的动画的一些"帧"(参见图片 - 圈子填充从0%到25%)
码
我创建绿色笔划(外部):
let ovalPath = UIBezierPath(ovalInRect: CGRectMake(20, 20, 240, 240))
let circleStrokeLayer = CAShapeLayer()
circleStrokeLayer.path = ovalPath.CGPath
circleStrokeLayer.lineWidth = 20
circleStrokeLayer.fillColor = UIColor.clearColor().CGColor
circleStrokeLayer.strokeColor = colorGreen.CGColor
containerView.layer.addSublayer(circleStrokeLayer)
Run Code Online (Sandbox Code Playgroud)
我创建填充形状的初始路径(内部):
let filledPathStart = UIBezierPath(arcCenter: CGPoint(x: 140, y: 140), radius: 120, startAngle: startAngle, endAngle: Math().percentToRadians(0), clockwise: true)
filledPathStart.addLineToPoint(CGPoint(x: 140, y: 140))
filledLayer = CAShapeLayer()
filledLayer.path = filledPathStart.CGPath
filledLayer.fillColor = colorGreen.CGColor
containerView.layer.addSublayer(filledLayer)
Run Code Online (Sandbox Code Playgroud)
然后我使用for循环和CABasicAnimations数组进行动画处理.
var animations: [CABasicAnimation] = [CABasicAnimation]()
func animate() {
for val …Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,我必须在我的圆圈上显示一个填充弧,这将指示所选时间.我附上了一张图片,用于说明我想要问的内容: -

请帮我介绍如何在圆上绘制圆弧.
任何建议将受到高度赞赏.
ios ×4
iphone ×3
ipad ×2
animation ×1
caanimation ×1
objective-c ×1
quartz-2d ×1
swift ×1
xcode ×1