I am trying to expand a circle from Zero radius to a predefined radius at the centre of the screen. The code is as follows
In viewDidLoad:-
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[super viewDidLoad];
circleRadius = 0.0f;
circle = [CAShapeLayer layer];
[circle setAnchorPoint:CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2)];
[circle setFillColor:[UIColor redColor].CGColor];
[circle setStrokeColor:[UIColor colorWithWhite:0.9f alpha:0.7f].CGColor];
[circle setLineWidth:0.0f];
[self.view.layer addSublayer:circle];
[self drawCircleWithRadius:circleRadius];
}
- (void)animateImageView {
circleRadius += 70.0f;
[self drawCircleWithRadius:circleRadius];
}
- (void)drawCircleWithRadius:(CGFloat)radius {
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
[pathAnimation setFromValue:(id)circle.path];//(id)circle.path
[pathAnimation setToValue:(id)[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0f * radius, 2.0f * radius) cornerRadius:radius].CGPath];
[pathAnimation setDuration:0.5f];
[pathAnimation setRepeatCount:1.0f];
[pathAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) cornerRadius:radius].CGPath;
circle.position = CGPointMake(CGRectGetMidX(self.view.frame)-radius, CGRectGetMidY(self.view.frame)-radius);
[circle addAnimation:pathAnimation forKey:@"changePathAnimation"];
}
-animateImageView runs on the tap of a bar button. Somehow the animation is not as smooth and the circle is not seeming to grow form the centre of screen.
Please point out the mistake in the code. Thanks.