iPhone MapKit:自定义MKPolygonView,图像颠倒

dub*_*ugh 1 iphone image cgcontext mapkit

有谁知道如何解决这个问题:我自定义MKPolygonView中的图像是颠倒翻转的吗?

这个想法(这已经工作正常)有一个"SnowmapsOverlayView"类,它扩展了"MKPolygonView",它显示了一个图像.此图片在地图上具有默认位置和大小(充当Google Maps Web API中的GroundOverlay).这一切都正常,但图像颠倒显示.我尝试了以下选项,但没有结果:

传递UIImage.CGImage时,CGContextDrawImage将图像上下颠倒

感谢您的任何帮助或建议!

我的代码:

#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;
}
Run Code Online (Sandbox Code Playgroud)

dub*_*ugh 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();
}
Run Code Online (Sandbox Code Playgroud)