我正在試圖在MKMapView上製作雷達圖像的動畫。我有不同的時間單獨的圖像,並且我已經成功地將圖像設置爲MKMapView頂部的覆蓋圖。我的問題是,當我試圖以一個接一個的順序顯示這些不同的圖像時。我嘗試了一種添加和刪除疊加層的方法,但是系統並沒有很好地處理它,疊加層閃爍,一些覆蓋層沒有被刪除,總體而言,它不值得。MKMapView Overlay(圖像動畫)
誰能幫我找到一種方式來顯示在MapView類的多張圖像(如GIF動畫)的方式,是順利和快速?
這裏是我的代碼,以覆蓋圖像:
- (id)initWithImageData:(NSData*)imageData withLowerLeftCoordinate:(CLLocationCoordinate2D)lowerLeftCoordinate withUpperRightCoordinate:(CLLocationCoordinate2D)upperRightCoordinate {
self.radarData = imageData;
MKMapPoint lowerLeft = MKMapPointForCoordinate(lowerLeftCoordinate);
MKMapPoint upperRight = MKMapPointForCoordinate(upperRightCoordinate);
mapRect = MKMapRectMake(lowerLeft.x, upperRight.y, upperRight.x - lowerLeft.x, lowerLeft.y - upperRight.y);
return self;
}
- (CLLocationCoordinate2D)coordinate
{
return MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMidX(mapRect), MKMapRectGetMidY(mapRect)));
}
- (MKMapRect)boundingMapRect
{
return mapRect;
}
這裏就是我如何設置它上的MapView:
- (void)drawMapRect:(MKMapRect)mapRect
zoomScale:(MKZoomScale)zoomScale
inContext:(CGContextRef)ctx
{
MapOverlay *mapOverlay = (MapOverlay *)self.overlay;
image = [[UIImage alloc] initWithData:mapOverlay.radarData];
MKMapRect theMapRect = [self.overlay boundingMapRect];
CGRect theRect = [self rectForMapRect:theMapRect];
@try {
UIGraphicsBeginImageContext(image.size);
UIGraphicsPushContext(ctx);
[image drawInRect:theRect blendMode:kCGBlendModeNormal alpha:0.5];
UIGraphicsPopContext();
UIGraphicsEndImageContext();
}
@catch (NSException *exception) {
NSLog(@"Caught an exception while drawing radar on map - %@",[exception description]);
}
@finally {
}
}
這裏的地方,我將疊加層:
- (void)mapRadar {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.mapOverlay = [[MapOverlay alloc] initWithImageData:appDelegate.image withLowerLeftCoordinate:CLLocationCoordinate2DMake(appDelegate.south, appDelegate.west) withUpperRightCoordinate:CLLocationCoordinate2DMake(appDelegate.north, appDelegate.east)];
[self.mapView addOverlay:self.mapOverlay];
[self.mapView setNeedsDisplay];
self.mapView.showsUserLocation = YES;
MKMapPoint lowerLeft2 = MKMapPointForCoordinate(CLLocationCoordinate2DMake(appDelegate.south2, appDelegate.west2));
MKMapPoint upperRight2 = MKMapPointForCoordinate(CLLocationCoordinate2DMake(appDelegate.north2, appDelegate.east2));
MKMapRect localMapRect = MKMapRectMake(lowerLeft2.x, upperRight2.y, upperRight2.x - lowerLeft2.x, lowerLeft2.y - upperRight2.y);
[self.mapView setVisibleMapRect:localMapRect animated:YES];
}
#pragma Mark - MKOverlayDelgateMethods
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay{
if([overlay isKindOfClass:[MapOverlay class]]) {
MapOverlay *mapOverlay = overlay;
self.mapOverlayView = [[MapOverlayView alloc] initWithOverlay:mapOverlay];
}
return self.mapOverlayView;
}
有沒有人有一個想法或解決方案,我可以順利地顯示一個MKMapView的圖像序列?在這一點上,我渴望解決方案,無法在其他任何地方找到它,所以任何事情都能幫助我,謝謝!
你爲什麼不使用與animaionImages一個的UIImageView? – Lefteris
@Lefteris我會,除了用戶可以放大地圖並移動它。你知道一種方法,可以將圖像視圖保持在同一位置,並在用戶縮放或平移時適當縮放圖像視圖嗎? – sridvijay
您可以將它作爲自定義placeMark或自定義註釋查看 – Lefteris