1

カスタム MKPolygonView の私の画像が上下逆になっていますか?

アイデア(これはすでに正常に機能しています)は、画像を表示する「MKPolygonView」を拡張するクラス「SnowmapsOverlayView」を持っています。この画像には、マップ上のデフォルトの位置とサイズがあります (Google マップ Web API で GroundOverlay として機能します)。これはすべて正常に機能していますが、画像が上下逆に表示されます。次のオプションを試しましたが、結果はありません。

CGContextDrawImage は、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;
}
4

2 に答える 2

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();
}
于 2010-08-30T10:11:30.693 に答える
0

MKPolygonView の代わりに MKOverlayView をサブクラス化してみましたか? ポリゴン クラスは、その座標系に対して奇妙なことを行う可能性があります。

于 2010-08-27T18:24:34.390 に答える