【问题标题】:Animated Radar Overlay MKMapView iOS动画雷达覆盖 MKMapView iOS
【发布时间】:2015-04-08 17:10:22
【问题描述】:

我正在从当前天气雷达的 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 动画,以实现您在新闻中看到的类似雷达的天气。我找到了几个可以做到这一点的应用程序,我想知道如何将它整合到我自己的项目中。

【问题讨论】:

    标签: ios objective-c mkmapview mkoverlay


    【解决方案1】:

    您提供的链接实际上并未显示动画 gif。它只是检索最新的 gif。一种方法是加载 NOAA 上传的最新 10-20 gif here,他们似乎每 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];
    

    【讨论】:

    • 你能解释一下网址,主要是网址的结尾/Conus... 我如何在不硬编码网址的情况下加载最后10张图片?
    • Conus 也表示连续的美国吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多