iPhone MapKit:带有图像的自定义MKPolygonView上下颠倒 [英] iPhone MapKit: Custom MKPolygonView with image draws upside down

查看:96
本文介绍了iPhone MapKit:带有图像的自定义MKPolygonView上下颠倒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何处理此问题:我的自定义MKPolygonView中的图像上下颠倒了吗?

does anybody know what to do with this problem: my image in a custom MKPolygonView is flipped upside down?

这个想法(这已经可以正常工作了)是拥有一个类"SnowmapsOverlayView",该类扩展了"MKPolygonView",并显示图像.此图片的默认位置为&地图上的尺寸(在Google Maps网络API中充当GroundOverlay).一切正常,但图像显示为上下颠倒.我尝试了以下选项,但没有结果:

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在通过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;
}

推荐答案

已修复!这是完成工作的代码:

Fixed! This is the code that gets the job done:

-(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();
}

这篇关于iPhone MapKit:带有图像的自定义MKPolygonView上下颠倒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆