【发布时间】:2013-10-19 20:53:25
【问题描述】:
在 iOS 7 中,MKOverlayView 被 MKOverlayRenderer 取代。之前,我可以将UIImageView 作为子视图添加到MKOverlayView,并访问MKOverlayView 的CALayer。现在,没有UIView 进入MKOverlayRenderer,我不确定如何添加自定义CALayer(我有一个快速浏览一系列图片的CAKeyFrameAnimation)。我如何将UIImageView 添加到MKOverlayRenderer 中?如何在CGContextRef 中添加CALayer(由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];
}
感谢任何帮助,谢谢!
【问题讨论】:
-
我遇到了同样的问题,stackoverflow.com/questions/20558591/…。希望 Stack Overflow 上的人能帮助我们。如果您解决了这个问题,请告诉我。
-
也许可以尝试在计时器上调用 -setNeedsDisplayInMapRect:zoomScale: 以将其标记为脏,以便再次调用您的 drawMapRect。
-
这里有什么更新吗?
标签: ios objective-c core-graphics mkmapview core-animation