我想通過繼承MKAnnotationView
並覆蓋drawRect
方法來製作自定義註釋視圖。我希望繪製的視圖與註釋的位置偏移,有點像MKPinAnnotationView
這樣做,以便引腳的點位於指定的座標處,而不是引腳中間。所以我設置了框架的位置和大小,如下所示。但是,它看起來並不像我可以影響框架的位置,只有尺寸。圖像最終以註釋位置爲中心繪製。有關如何實現我想要的任何提示?如何更改自定義MKAnnotationView的框架位置?
MyAnnotationView.h:
@interface MyAnnotationView : MKAnnotationView {
}
MyAnnotationView.m:
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) {
self.canShowCallout = YES;
self.backgroundColor = [UIColor clearColor];
// Position the frame so that the bottom of it touches the annotation position
self.frame = CGRectMake(0, -16, 32, 32);
}
return self;
}
- (void)drawRect:(CGRect)rect {
[[UIImage imageNamed:@"blue-dot.png"] drawInRect:rect];
}
是
回答,對於基於圖像的標註視圖的工作(這實際上是足夠的,我的目的)。但我仍然對一般情況感到好奇。 – andrei 2010-03-21 05:56:14