Apollo
Apollo

Reputation: 9062

Creating an expanding circle iOS

How would go about creating a circle that expands overtime. I want to do something like this:

[UIView animateWithDuration:5 animations:^(void){

   /* Expand the circle */

    // Get the contextRef
    CGContextRef contextRef = UIGraphicsGetCurrentContext();

    // Set the border width
    CGContextSetLineWidth(contextRef, 1.0);

    // Set the circle fill color to Transparent
    CGContextSetRGBFillColor(contextRef, 0.0, 0.0, 0.0, 0.0);

    // Set the cicle border color to BLUE
    CGContextSetRGBStrokeColor(contextRef, 0.0, 0.0, 255.0, 1.0);

    // Fill the circle with the fill color
    CGContextFillEllipseInRect(contextRef, self.view.frame);

    // Draw the circle border
    CGContextStrokeEllipseInRect(contextRef, self.view.frame);
}];

Upvotes: 2

Views: 3732

Answers (1)

SomeGuy
SomeGuy

Reputation: 9690

That drawing code will have no affect in an animation block

Try the following instead:

// Create a view with a corner radius as the circle
UIView* circle = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
[circle.layer setCornerRadius:circle.frame.size.width / 2];
[circle setBackgroundColor:[UIColor redColor]];
[self.view addSubview:circle];

[UIView animateWithDuration:5 animations:^{

    // Animate it to double the size
    const CGFloat scale = 2;
    [circle setTransform:CGAffineTransformMakeScale(scale, scale)];
}];

Upvotes: 5

Related Questions