2015-02-09 86 views
1

我從目前的氣象雷達的NOAA獲取一個GIF,我把它保存在一個UIImage,然後畫上了MKMapView,這裏是一些我使用的代碼:動畫雷達覆蓋的MKMapView的iOS

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

您提供的鏈接實際上並未顯示動畫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]; 
+0

能否請你解釋一下網址,主要是網址的結尾'/芋...'我怎麼會去加載最後10張沒有硬編碼的網址是什麼? – Clip 2015-02-10 16:19:56

+0

Conus也意味着連續的美國? – Clip 2015-02-10 16:29:12