2012-04-16 79 views
2

我想在地圖上設置自定義圖像而不是普通的圖釘。我也希望它能夠被打開併爲每個添加drop標籤。MKPinAnnotationView自定義圖像

有什麼建議嗎?

編輯:這是我的所有

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(ActivityAnnotation *)annotation 
{ 
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier"; 
    MKPinAnnotationView* pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier]; 
    pinView.animatesDrop=YES; 
    pinView.canShowCallout=YES; 
    UIImage *image = [UIImage imageNamed:@"Map_Pin"]; 
    pinView.image = image; 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
    imageView.frame = CGRectMake(-2.5,6,27,30); 
    [pinView addSubview:imageView]; 
    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    rightButton.tag = [activities indexOfObject:annotation.activity]; 
    [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside]; 
    pinView.rightCalloutAccessoryView = rightButton; 

    return pinView; 
} 

一切工作正常,但原來的腳不斷得到背後顯示我的默認圖像。我怎樣才能抹去它?

回答

6

嘗試不使用MKPinAnnotationView,而是使用MKAnnotationView。 MKPinAnnotationView默認顯示一個引腳,只允許您自定義顏色(如果我沒有弄錯)。 MKAnnotationView允許定製圖釘。

+0

是的,但如果我使用MKAnnotationView,我該如何製作animatesDrop動畫? – sergiocg90 2012-04-16 15:03:13

+1

然後你必須自己動手。計算地圖座標的頂部有點煩人,但它是框架位置上的簡單動畫。 – 2012-04-16 15:10:20

+0

https://gist.github.com/2399387這個要點是我如何使用自定義動畫放置我的MKAnnotationView的例子。 – 2012-04-16 15:14:29