2

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);
}];
Apollo
  • 8,874
  • 32
  • 104
  • 192
  • it's trivial to animate the size of the frame, see many examples e.g. http://stackoverflow.com/a/6728458/294884 – Fattie Oct 23 '14 at 10:37
  • the way to "really do this" is to use the amazing .. http://paintcodeapp.com – Fattie Oct 24 '14 at 16:23

1 Answers1

5

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)];
}];
SomeGuy
  • 9,670
  • 3
  • 32
  • 35
  • Hey man - wouldn't it be much much better to just animate the **size of the frame** ?? – Fattie Oct 23 '14 at 10:36
  • @JoeBlow Blow That's what I initially tried, however then you also need to animate the corner radius, and that gave me problems. I'm sure it's possible, just don't know how. – SomeGuy Oct 23 '14 at 11:29
  • @SomeGuy would you mind taking a look at this question I just posted? Thanks! http://stackoverflow.com/questions/26538788/logarithmic-scale-for-animation-objective-c – Apollo Oct 23 '14 at 22:53