Search code examples
iphoneanimationcore-animation

How to do a radar animation in the iPhone SDK?


Does anyone know how to animate a radar animation like the image below? alt text http://img197.imageshack.us/img197/7124/circle0.png

With it growing outwards? I have to draw the circle using Quartz or some other way?


Solution

  • To draw a static circle in a UIView subclass:

    - (void)drawRect:(CGRect)rect
    {
        CGRect rect = { 0.0f, 0.0f, 100.0f, 100.0f };
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
        CGContextSetLineWidth(context, 2.0f);
        CGContextAddEllipseInRect(context, rect);
        CGContextStrokePath(context);
    }
    

    From there you just need to animate it with a timer, vary the size of the rect, and add more circles.