11

在 iOS 7 中,MKOverlayViewMKOverlayRenderer. 之前,我可以将 aUIImageView作为子视图添加到,MKOverlayView并访问CALayer. MKOverlayView现在,没有UIView进去MKOverlayRenderer,我不确定如何添加自定义CALayer(我有一个CAKeyFrameAnimation快速浏览一系列图片的)。我将如何添加UIImageViewMKOverlayRenderer?我将如何CALayer在 a 中添加CGContextRef(由 使用MKOverlayRenderer)?

我尝试自己做,但它根本没有通过图像。

- (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];

}

任何帮助表示赞赏,谢谢!

4

1 回答 1

-1

尝试添加以下代码

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

并使用 NSMutableArray 而不是 NSArray。

于 2014-01-30T09:32:43.913 回答