Iphone 在地图中将UIView子类化以绘制线

Iphone 在地图中将UIView子类化以绘制线,iphone,uiview,ios4,uiscrollview,subclass,Iphone,Uiview,Ios4,Uiscrollview,Subclass,我有一个显示自定义地图的应用程序。我使用CATiledView显示地图 我希望能够在地图的顶部画一条路线。为此,我创建了一个UIView,然后在添加平铺层后将其添加到scrollView,如下所示: - (void)displayTiledImageNamed:(NSString *)imageName size:(CGSize)imageSize { // clear the previous imageView [imageView removeFromSuperview];

我有一个显示自定义地图的应用程序。我使用CATiledView显示地图

我希望能够在地图的顶部画一条路线。为此,我创建了一个UIView,然后在添加平铺层后将其添加到scrollView,如下所示:

- (void)displayTiledImageNamed:(NSString *)imageName size:(CGSize)imageSize
{
    // clear the previous imageView
    [imageView removeFromSuperview];
    [imageView release];
    imageView = nil;
    [linesView removeFromSuperview];
    [linesView release];
    linesView = nil;

    // reset our zoomScale to 1.0 before doing any further calculations
    self.zoomScale = 1.0;

    // make a new TilingView for the new image
    imageView = [[TilingView alloc] initWithImageName:imageName size:imageSize];
    linesView = [[LinesView alloc]initWithImageName:imageName size:imageSize];

    linesView.backgroundColor = [UIColor clearColor];
    [self addSubview:imageView];
    [self addSubview:linesView];
    [self configureForImageSize:imageSize];


}
- (void)displayTiledImageNamed:(NSString *)imageName size:(CGSize)imageSize
{
    // clear the previous imageView
    [imageView removeFromSuperview];
    [imageView release];
    imageView = nil;
    [linesView removeFromSuperview];
    [linesView release];
    linesView = nil;

    // reset our zoomScale to 1.0 before doing any further calculations
    self.zoomScale = 1.0;

    // make a new TilingView for the new image
    imageView = [[TilingView alloc] initWithImageName:imageName size:imageSize];
    linesView = [[LinesView alloc]initWithImageName:imageName size:imageSize];

    linesView.backgroundColor = [UIColor clearColor];
    [self addSubview:imageView];
    [imageView addSubview:linesView];
    [self configureForImageSize:imageSize];


}
问题是,我在linesView中创建的线没有正确缩放

这很难描述,但正在创建的线是按比例缩放的,就好像它是在设备本身上绘制的,而不是在地图上绘制的一样。请参阅以下代码:

#import "LinesView.h"


@implementation LinesView
@synthesize imageName;


- (id)initWithImageName:(NSString *)name size:(CGSize)size
{
    if ((self = [super initWithFrame:CGRectMake(0, 0, size.width, size.height)])) {
        self.imageName = name;

    }

    return self;
}
- (void)dealloc
{
    [super dealloc];
}

- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);
    CGContextSetLineWidth(context, 20.0);
    CGContextMoveToPoint(context, 1.0f, 220.0f);
    CGContextAddLineToPoint(context, 340.0f, 80);
    CGContextStrokePath(context);
}

@end
我已经尝试过将代码放在tilingView的drawRect方法中画线,它工作得非常好。相对于贴图,线宽为20px。在Lines视图中,该行相对于设备宽20px,相对于scrollview定位


抱歉,我正在尽力描述问题…

解决了这个问题-我将linesView添加到平铺视图,而不是滚动视图,如下所示:

- (void)displayTiledImageNamed:(NSString *)imageName size:(CGSize)imageSize
{
    // clear the previous imageView
    [imageView removeFromSuperview];
    [imageView release];
    imageView = nil;
    [linesView removeFromSuperview];
    [linesView release];
    linesView = nil;

    // reset our zoomScale to 1.0 before doing any further calculations
    self.zoomScale = 1.0;

    // make a new TilingView for the new image
    imageView = [[TilingView alloc] initWithImageName:imageName size:imageSize];
    linesView = [[LinesView alloc]initWithImageName:imageName size:imageSize];

    linesView.backgroundColor = [UIColor clearColor];
    [self addSubview:imageView];
    [self addSubview:linesView];
    [self configureForImageSize:imageSize];


}
- (void)displayTiledImageNamed:(NSString *)imageName size:(CGSize)imageSize
{
    // clear the previous imageView
    [imageView removeFromSuperview];
    [imageView release];
    imageView = nil;
    [linesView removeFromSuperview];
    [linesView release];
    linesView = nil;

    // reset our zoomScale to 1.0 before doing any further calculations
    self.zoomScale = 1.0;

    // make a new TilingView for the new image
    imageView = [[TilingView alloc] initWithImageName:imageName size:imageSize];
    linesView = [[LinesView alloc]initWithImageName:imageName size:imageSize];

    linesView.backgroundColor = [UIColor clearColor];
    [self addSubview:imageView];
    [imageView addSubview:linesView];
    [self configureForImageSize:imageSize];


}