iPhone MapKit:自定义 MKPolygonView,图像绘制颠倒
有谁知道如何解决这个问题:我在自定义 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;
}
does anybody know what to do with this problem: my image in a custom MKPolygonView is flipped upside down?
The idea (this is working OK already) is having an class "SnowmapsOverlayView" that extends "MKPolygonView", that displays a image. This image has a default location & size on the map (acts as a GroundOverlay in the Google Maps web API). This is all working fine, but the image is displayed upside down. I've tryed the following options, but with no result:
CGContextDrawImage draws image upside down when passed UIImage.CGImage
Thanks for any help or suggestions!
My code:
#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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
固定的!这是完成工作的代码:
Fixed! This is the code that gets the job done:
您是否尝试过子类化 MKOverlayView 而不是 MKPolygonView ?多边形类可能会对它的坐标系做一些奇怪的事情。
Have you tried subclassing MKOverlayView instead of MKPolygonView? The polygon class may do something weird to its coordinate system.