Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone MapKit:自定义MKPolygonView,图像绘制颠倒_Iphone_Image_Mapkit_Cgcontext - Fatal编程技术网

iPhone MapKit:自定义MKPolygonView,图像绘制颠倒

iPhone MapKit:自定义MKPolygonView,图像绘制颠倒,iphone,image,mapkit,cgcontext,Iphone,Image,Mapkit,Cgcontext,有人知道该怎么处理这个问题吗:自定义MKPolygonView中的图像是颠倒的 这个想法已经奏效了,就是有一个类SnowmapsOverlayView,它扩展了MKPolygonView,可以显示图像。此图像在地图上具有默认位置和大小,在Google Maps web API中用作地面覆盖。这一切工作正常,但图像显示颠倒。我尝试了以下选项,但没有结果: 谢谢你的帮助和建议 我的代码: #import <MapKit/MapKit.h> @interface SnowmapsOver

有人知道该怎么处理这个问题吗:自定义MKPolygonView中的图像是颠倒的

这个想法已经奏效了,就是有一个类SnowmapsOverlayView,它扩展了MKPolygonView,可以显示图像。此图像在地图上具有默认位置和大小,在Google Maps web API中用作地面覆盖。这一切工作正常,但图像显示颠倒。我尝试了以下选项,但没有结果:

谢谢你的帮助和建议

我的代码:

#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;
}

您是否尝试过子类化MKOverlayView而不是MKPolygonView?polygon类可能会对其坐标系做一些奇怪的事情。

您是否尝试过将MKOverlayView子类化,而不是将MKPolygonView子类化?多边形类可能会对其坐标系做一些奇怪的事情。

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

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

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

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

你刚刚帮我解决了一个大问题。。谢谢你刚刚帮我解决了一个大问题。。谢谢UIImage方法在绘制时考虑方向,CGImage方法不考虑方向。UIImage方法在绘制时考虑方向,CGImage方法不考虑方向。