我已经对MKAnnotatonView
进行了子类化,并覆盖了initWithAnnotation:resueIdentifier
和drawRect
方法,以在“前面”图像后添加另一张图像。
看起来这就是苹果的MKAnnotationView
类参考所建议的做法。
但是这很棘手。如果你正在对MKAnnotationView
进行子类化,那么仍然存在image属性。他们已经对该属性进行了一些处理,使其与绘制相关联。也许,他们已经覆盖了drawRect方法,在初始化完成后绘制图像。
此外,如果您没有设置image属性,则自定义annotationView
的框架大小将被设置为0,并且drawRect
方法不会被调用。
最后,苹果表示图像应完全填充,即使用透明颜色作为绘画背景。
因此,在您的子类中:
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)identifier
{
self = [super initWithAnnotation:annotation reuseIdentifier:identifier];
if (self)
{
UIButton *rightButton = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:@selector(myShowAnnotationAddress:)
forControlEvents:UIControlEventTouchUpInside];
self.rightCalloutAccessoryView = rightButton;
self.canShowCallout = YES;
self.multipleTouchEnabled = NO;
self.frame = CGRectMake(0, 0, 65, 100);
self.backgroundColor = [UIColor clearColor];
return self;
}
return nil;
}
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGPoint drawPoint = CGPointMake(0.0f, 0.0f);
UIImage *shadowImage = [UIImage imageNamed:@"shadow_image.png"];
[shadowImage drawAtPoint:drawPoint];
UIImage *frontImage = [UIImage imageNamed:@"front_image.png"];
[frontImage drawAtPoint:drawPoint];
CGContextRestoreGState(context);
}
在我回答问题后,我意识到你实际上想在
MKPinAnnotationView
后面绘制。我的回答并不是那样的,尽管它展示了可能应该进行绘制的位置。显然
MKPinAnnottions
有其自己的绘制方法来呈现一个图钉及其阴影。
我认为你可以从self.image属性中检索出图钉图像。至于阴影,我不确定......它可能使用OPEN GL绘图方法添加阴影,或者简单地组合一个阴影图像。
最后,图像带有动画效果。我猜测那就是动画运行的地方。不过,在这个阶段,我还没有测试过。