GIF animado não funciona na sobreposição do MKMapView usando o MKOverlayRenderer
Estou tentando exibir um gif animado em uma sobreposição paraMKMapView
. A sobreposição é criada usando oMKOverlayRenderer
. Para animar o gif no iOS 7, estou usando oUIImage+animatedGIF
categoria postadaAqui no GitHub.
A imagem do gif animado é exibida na sobreposição usando a categoria; no entanto, o gif não anima. Eu não tenho nenhum problema usando a categoria para animar um gif em umUIImageView
mas parece não funcionar corretamente em uma sobreposição de exibição de mapa.
Como posso usar essa categoria para colocar um gif animado em uma sobreposição de exibição de mapa?
ou...
Existe uma maneira de colocar umUIImageView
na sobreposição que pode resolver o meu problema, definindo oUIImageView
com o gif animado?
Minha subclasse de renderizador de sobreposição é a seguinte:
MapOverlayRenderer.h
#import <MapKit/MapKit.h>
@interface MapOverlayRenderer : MKOverlayRenderer
- (instancetype)initWithOverlay:(id<MKOverlay>)overlay overlayImage:(UIImage *)overlayImage;
@end
MapOverlayRenderer.m
#import "MapOverlayRenderer.h"
@interface MapOverlayRenderer ()
@property (strong,nonatomic) UIImage *image;
@end
@implementation MapOverlayRenderer
- (instancetype)initWithOverlay:(id<MKOverlay>)overlay overlayImage:(UIImage *)overlayImage {
self = [super initWithOverlay:overlay];
if (self) {
_image = overlayImage;
}
return self;
}
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
CGImageRef imageReference = self.image.CGImage;
MKMapRect theMapRect = [self.overlay boundingMapRect];
CGRect theRect = [self rectForMapRect:theMapRect];
CGContextScaleCTM(context, 1.0, -1.0);
CGContextTranslateCTM(context, 0.0, -theRect.size.height);
CGContextDrawImage(context, theRect, imageReference);
}
@end
No meuUIViewController
, Estou buscando o gif animado e adicionando a sobreposição chamando um método que contém o seguinte código:
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:[NSURL URLWithString:radarUrl] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
self.radarImage = [UIImage animatedImageWithAnimatedGIFData:data]; //for animated radar image
dispatch_async(dispatch_get_main_queue(), ^{
[self.mapView addOverlay:self.polygon];
});
}] resume];
Qualquer sugestão sobre como animar um gif em uma sobreposição de visualização de mapa do iOS 7 seria muito apreciada.