有人知道該怎麼做這個問題:我的圖像在自定義MKPolygonView翻轉顛倒?iPhone MapKit:帶圖像的自定義MKPolygonView繪製倒過來
這個想法(這是工作正常)已經有一個類「SnowmapsOverlayView」,擴展「MKPolygonView」,顯示圖像。此圖片在地圖上的默認位置爲&(用作Google Maps Web API中的GroundOverlay)。這一切工作正常,但圖像倒過來顯示。我tryed以下選項,但沒有結果:
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;
}
你剛幫我解決了一個大問題..謝謝! – 2011-05-27 10:54:19