有人知道如何解决这个问题:我在自定义 MKPolygonView 中的图像被颠倒了吗?
这个想法(这已经可以了)是有一个扩展“MKPolygonView”的类“SnowmapsOverlayView”,它显示一个图像。此图像在地图上具有默认位置和大小(在 Google Maps 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;
}