有人知道如何处理这个问题:我自定义的MKPolygonView中的图像是颠倒翻转的吗?
这个想法(这已经可以了)已经有了一个“SnowmapsOverlayView”类,它扩展了“MKPolygonView”,它显示了一个图像。此图片具有默认位置&地图上的尺寸(充当Google Maps网络API中的GroundOverlay)。这一切都正常,但图像颠倒显示。我尝试了以下选项,但没有结果:
CGContextDrawImage draws image upside down when passed UIImage.CGImage
感谢您提供任何帮助或建议!
我的代码:
#import <MapKit/MapKit.h>
@interface SnowmapsOverlayView : MKPolygonView
{
}
@end
-----------------
#import "SnowmapsOverlayView.h"
@implementation SnowmapsOverlayView
-(id)initWithPolygon:(MKPolygon *)polygon
{
self = [super initWithPolygon:polygon];
return self;
}
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
{
UIImage *image = [UIImage imageNamed:@"snowmap.png"];
//This should do the trick, but is doesn't.. maybe a problem with the "context"?
//CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);
//CGContextTranslateCTM(context, 0, image.size.height);
//CGContextScaleCTM(context, 1.0, -1.0);
CGRect overallCGRect = [self rectForMapRect:self.overlay.boundingMapRect];
CGContextDrawImage(context, overallCGRect, image.CGImage);
}
-(BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale
{
return YES;
}
答案 0 :(得分:8)
固定!这是完成工作的代码:
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
{
UIImage *image = [UIImage imageNamed:@"snowmap.png"];
MKMapRect theMapRect = [self.overlay boundingMapRect];
CGRect theRect = [self rectForMapRect:theMapRect];
UIGraphicsPushContext(context);
[image drawInRect:theRect blendMode:kCGBlendModeNormal alpha:1.0];
UIGraphicsPopContext();
}
答案 1 :(得分:0)
您是否尝试过继承MKOverlayView而不是MKPolygonView?多边形类可能会对其坐标系做一些奇怪的事情。