我试图在一张美国地图上绘制一系列雷达图像。我有一张从NOAA网站下载的雷达gif图像列表。
如何在mapkit覆盖层上实现一系列图像的动画?我在这里看到过这样的帖子:动画MKOverlayView和动画化MKOverlayView
但没能找到解决办法。
发布于 2014-05-14 16:18:11
我通过在视图控制器中创建一个计时器来解决这个问题。每次计时器触发时,它都会为我的自定义setNeedsDisplay调用MKOverlayRenderer方法。在呈现器子类drawMapRect方法中,我有以下代码来更新覆盖层上的图像:
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context{
if (!weatherDataStore) //This is the store where I have my radar images
weatherDataStore = [WeatherDataStore sharedInstance];
UIImage *image = [weatherDataStore currentRadarImage];
if (!image || ![image isKindOfClass:[UIImage class]]) {
return;
}
CGImageRef imageReference = image.CGImage;
CGContextSetAlpha(context, 0.8);
MKMapRect theMapRect = [self.overlay boundingMapRect];
CGRect theRect = [self rectForMapRect:theMapRect];
CGContextScaleCTM(context, 1.0, -1.0);
CGContextTranslateCTM(context, 0.0, -theRect.size.height);
CGContextDrawImage(context, theRect, imageReference);
}发布于 2014-01-22 19:23:55
以下是iOS7的最佳解决方案。MKOverlayRenderer使向MKMapkit添加动画变得非常困难。遵循这个项目中的示例。
https://stackoverflow.com/questions/19062937
复制相似问题