简体   繁体   English

动画雷达叠加MKMapView iOS

[英]Animated Radar Overlay MKMapView iOS

I am fetching a gif from the NOAA of the current weather radar, I store it in a UIImage and then draw it to an MKMapView , here is some of the code I am using: 我正在从当前天气雷达的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 {

}

Does anyone know how I can animate this gif repeatedly to achieve a weather like radar you see on the news. 有谁知道我怎样才能反复给这个gif动画,以实现新闻中看到的像雷达这样的天气。 I have found several apps that do this and am wondering how I can incorporate it into my own project. 我发现有几个应用程序可以做到这一点,并且想知道如何将其合并到自己的项目中。

The link you provided doesn't actually show an animated gif. 您提供的链接实际上并未显示动画gif。 It just retrieves the latest gif. 它只是检索最新的gif。 One way you could do it is load the latest 10-20 gif's the NOAA has uploaded here , they seem to update it every 10 minutes, then create a UIImage for each gif and cycle through them in a UIImageview which overlays your map. 一种可能的方法是,将最新的10-20 gif文件加载到NOAA已上传到这里的文件中 ,他们似乎每10分钟更新一次,然后为每个gif文件创建一个UIImage并在覆盖地图的UIImageview循环浏览。 For example: 例如:

// 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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM