Is it possible to create a custom, animated MKAnnotationView?

Posted by smountcastle on Stack Overflow See other posts from Stack Overflow or by smountcastle
Published on 2010-04-21T13:47:40Z Indexed on 2010/04/21 14:23 UTC
Read the original article Hit count: 557

Filed under:
|
|

I'm trying to simulate the user location animation in MapKit (where-by the user's position is represented by a pulsating blue dot). I've created a custom subclass of MKAnnotationView and in the drawRect method I'm attempting to cycle through a set of colors. Here's a simpler implementation of what I'm doing:

- (void)drawRect:(CGRect)rect {
float magSquared = event.magnitude * event.magnitude;
CGContextRef context = UIGraphicsGetCurrentContext();
if (idx == -1) {
    r[0] = 1.0; r[1] = 0.5; r[2] = 0;
    b[0] = 0; b[1] = 1.0; b[2] = 0.5;
    g[0] = 0.5; g[1] = 0; g[2] = 1.0;
    idx = 0;
}
// CGContextSetRGBFillColor(context, 1.0, 1.0 - magSquared * 0.015, 0.211, .6);
CGContextSetRGBFillColor(context, r[idx], g[idx], b[idx], 0.75);
CGContextFillEllipseInRect(context, rect);
idx++;
if (idx > 3) idx = 0;
}

Unfortunately this just causes the annotations to be one of the 3 different colors and doesn't cycle through them. Is there a way to force the MKAnnotations to continually redraw so that it appears to be animated?

© Stack Overflow or respective owner

Related posts about mapkit

Related posts about iphone