我已將子類別MKAnnotatonView
並覆蓋了initWithAnnotation:resueIdentifier
和drawRect
方法在「前」圖像後添加另一圖像。
看來這就是蘋果的MKAnnotationView
類參考所暗示的我們所要做的。
只是它很棘手。如果您繼承MKAnnotationView
,仍然存在圖像屬性。他們已經做了一些正確的事情,以便它與繪圖相關聯。也許,他們已經重寫了drawRect在初始化完成後繪製圖像。
此外,如果您未設置圖像屬性,則自定義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
有它自己的繪圖方法來呈現一個Pin和它的影子。
我想這可能是你可以從self.image屬性中獲取Pin圖像。至於陰影,我不確定...它可能使用OPEN GL繪圖方法來添加陰影,或者僅僅是組合陰影圖像。
最後,圖像自帶動畫。我猜測那是動畫運行的地方。但是在這個階段,我還沒有測試過。
如何隱藏這個引腳? – 2010-02-12 15:16:32
如果沒有MKPinAnnotationView,MKAnnotationView將不會響應觸摸。如何解決問題? – Satyam 2014-02-15 18:19:24