动画雷达覆盖MKMapView iOS

时间:2015-02-09 01:53:09

标签: ios objective-c mkmapview mkoverlay

我从NOAA获取当前天气雷达的GIF,我将其存储在UIImage中,然后将其绘制到MKMapView,这是我正在使用的一些代码:

image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://radar.weather.gov/ridge/Conus/RadarImg/latest_radaronly.gif"]]];

MKMapRect theMapRect    = [self.overlay boundingMapRect];
CGRect theRect           = [self rectForMapRect:theMapRect];

@try {
    UIGraphicsBeginImageContext(image.size);
    UIGraphicsPushContext(ctx);
    [image drawInRect:theRect];
    UIGraphicsPopContext();
    UIGraphicsEndImageContext();
}
@catch (NSException *exception) {
    NSLog(@"Caught an exception while drawing radar on map - %@",[exception description]);
}
@finally {

}

有谁知道如何反复动画这个gif来实现你在新闻中看到的雷达般的天气。我找到了几个这样做的应用程序,我想知道如何将它合并到我自己的项目中。

1 个答案:

答案 0 :(得分:1)

您提供的链接实际上并未显示GIF动画。它只是检索最新的gif。你可以做到的一种方法是加载NOAA上传here的最新10-20 gif,他们似乎每10分钟更新一次,然后为每个gif和周期创建一个UIImage通过它们覆盖地图的UIImageview。 例如:

// Set images
radarGIF01 = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://radar.weather.gov/ridge/Conus/RadarImg/Conus_20150209_0108_N0Ronly.gif"]]];
radarGIF02 = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://radar.weather.gov/ridge/Conus/RadarImg/Conus_20150209_0118_N0Ronly.gif"]]];
radarGIF03 = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://radar.weather.gov/ridge/Conus/RadarImg/Conus_20150209_0128_N0Ronly.gif"]]];
radarGIF04 = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://radar.weather.gov/ridge/Conus/RadarImg/Conus_20150209_0138_N0Ronly.gif"]]];
radarGIF05 = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://radar.weather.gov/ridge/Conus/RadarImg/Conus_20150209_0148_N0Ronly.gif"]]];

// Add images to array
radarImagesArray = [[NSArray alloc]initWithObjects: radarGIF01, radarGIF02, radarGIF03, radarGIF04, radarGIF05, nil];

// Animate images in UIImageview
_radarImageView.animationImages = radarImagesArray;
_radarImageView.animationDuration = 3.0;
_radarImageView.animationRepeatCount = 0;
[_radarImageView startAnimating];