2013-10-19 18 views
10

In iOS 7, MKOverlayView è stato sostituito da MKOverlayRenderer. Prima, sono stato in grado di aggiungere un come sottoview a MKOverlayView e accedere allo dello MKOverlayView. Ora, senza UIView inserito in MKOverlayRenderer, non sono sicuro su come aggiungere una personalizzata CALayer (ho uno CAKeyFrameAnimation che passa rapidamente attraverso una serie di immagini). Come aggiungerei un UIImageView a MKOverlayRenderer? Come aggiungerei un CALayer in un CGContextRef (utilizzato da MKOverlayRenderer)?Aggiunta di un CALayer a MKOverlayRenderer?

Ho provato a farlo da solo, ma non passa affatto attraverso le immagini.

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context { 
CGContextSaveGState(context); 

CGRect test = [self rectForMapRect:self.overlay.boundingMapRect]; 
// Clip the drawing space to the map rect 
CGRect clipRect = [self rectForMapRect:mapRect]; 

CGContextClipToRect(context, clipRect); 

// CoreGraphics' coordinate system is flipped, so we need to transform it first 
CGContextScaleCTM(context, 1.0, -1.0); 
CGContextTranslateCTM(context, 0, -test.size.height); 

// Draw the portion of the image in the map rect 

// CGContextDrawImage(context, test, [image CGImage]); 

CGContextRestoreGState(context); 

CALayer *sublayer = [CALayer layer]; 
sublayer.frame = test; 
NSArray *radarImages = [NSArray arrayWithObjects:(id)image.CGImage, image1.CGImage, image2.CGImage, image3.CGImage, image4.CGImage, image5.CGImage, image6.CGImage, image7.CGImage, image8.CGImage, image9.CGImage, image10.CGImage, image11.CGImage, image12.CGImage, image13.CGImage, image14.CGImage, image15.CGImage, image16.CGImage, image17.CGImage, image18.CGImage,image19.CGImage,image20.CGImage,image21.CGImage, image22.CGImage, image23.CGImage, image24.CGImage, nil]; 


anim = [CAKeyframeAnimation animation]; 
[anim setKeyPath:@"contents"]; 
[anim setCalculationMode:kCAAnimationDiscrete]; 
[anim setValues:radarImages]; 
[anim setRepeatCount:INFINITY]; 
[anim setDuration:2.6]; 
[self drawLayer:sublayer inContext:context]; 
[sublayer addAnimation:anim forKey:nil]; 
[sublayer renderInContext:context]; 
[sublayer setNeedsDisplay]; 

} 

Qualsiasi aiuto è apprezzato, grazie!

+0

Ho lo stesso problema, http://stackoverflow.com/questions/20558591/animated-gif-not-working-in-mkmapview-overlay-using-mkoverlayrenderer?noredirect=1#comment30789828_20558591. Speriamo che qualcuno su Stack Overflow ci aiuti. Per favore fatemi sapere se lo capite. – wigging

+0

Forse prova a chiamare -setNeedsDisplayInMapRect: zoomScale: su un timer per contrassegnarlo sporco in modo che drawMapRect venga nuovamente chiamato. – MindJuice

+0

eventuali aggiornamenti qui? –

risposta

-1

Prova ad aggiungere il seguente codice

 [[[self view] layer] addSublayer: sublayer]; 

e utilizzare NSMutableArray invece di NSArray.