简体   繁体   English

如何使用swift为在UIView中创建的CGContext设置动画?

[英]How to animate a CGContext created in a UIView using swift?

I have created a image as CGContext in a class which is a subclass of UIView class. 我已经在UIView类的子类中的类中创建了作为CGContext的图像。 I need to know how to animate this image. 我需要知道如何为该图像设置动画。 I need to animate this image such that it moves along a circle/arc. 我需要对此图像进行动画处理,以使其沿圆/弧移动。

the image is created using the following code: 使用以下代码创建图像:

let ctx = UIGraphicsGetCurrentContext()  
let rad = CGRectGetWidth(valueRect)/0.08  
let endAngle = CGFloat(2*M_PI)
CGContextSetShadowWithColor(ctx, CGSizeMake(0, 0), 10, UIColor(red: 0, green: 0, blue: 0, alpha: 0.35).CGColor)
CGContextAddArc(ctx, CGRectGetMidX(valueRect), CGRectGetMidY(valueRect), rad, 0, endAngle, 1)
CGContextSetFillColorWithColor(ctx,UIColor.whiteColor().CGColor)
CGContextFillPath(ctx)
CGContextSetLineWidth(ctx, 0.1)
CGContextStrokePath(ctx);

I need to animate the circle image in ctx along an arc of certain radius with a certain start and end angle. 我需要沿具有特定起点和终点角度的特定半径的圆弧在ctx对圆形图像进行动画处理。 Can anyone suggest a way to do it? 有人可以建议一种方法吗?

The easiest way is to animate the view that displays the image. 最简单的方法是对显示图像的视图进行动画处理。 You can easily animate a view along a path using keyframe animation. 您可以使用关键帧动画轻松地沿路径创建视图动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM