Reputation: 467
I need to animate the filling of a circular progress meter with a HUD-like pie animation. I've found examples of how to do this using Core Animation to animate a path in a solid color. The difference is that I need the fill to be an image mask (see link), not a solid color.
Click here to see design images
Can someone provide a suggestion on how to go about this using Core Animation or anything else?
Upvotes: 4
Views: 9793
Reputation: 6459
My example with magic numbers (for better understanding):
CAShapeLayer *circle = [CAShapeLayer layer];
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(29, 29) radius:27 startAngle:-M_PI_2 endAngle:2 * M_PI - M_PI_2 clockwise:YES].CGPath;
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor greenColor].CGColor;
circle.lineWidth = 4;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.duration = 10;
animation.removedOnCompletion = NO;
animation.fromValue = @(0);
animation.toValue = @(1);
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[circle addAnimation:animation forKey:@"drawCircleAnimation"];
[imageCircle.layer.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
[imageCircle.layer addSublayer:circle];
imageCircle - UIImageView with your custom "image mask".
Upvotes: 5
Reputation: 106
Here's the basic tutorial for circular progress view:
http://iosdevtricks.blogspot.com/2013/06/custom-circular-progress-view-for-ios.html
You will need to make a few additional adjustments:
Upvotes: 2
Reputation: 56625
If you already know how to do it with a solid color then all you need to do is to create a new layer use as the mask
of the image (the green circle). The alpha channel of the masking layer is used to determine what is visible so you could just use any of the examples you've already read that used a single color and use that for your mask. Properties of the mask layer can be animated to change it so that more or less of the image becomes visible.
So what you need to do is:
mask
of the blue imageViews layerUpvotes: 1