2012-05-08 73 views
0

我使用下面的代碼在我的mapview中設置了一個自定義註釋。問題在於註釋圖像的位置不正確,它將它放在實際位置的右側而不是像使用常規引腳時一樣點。自定義註釋錯誤

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
     return nil; 
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier"; 
    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier]; 
    if(annotationView) 
     return annotationView; 
    else 
    { 
     MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation 
                     reuseIdentifier:AnnotationIdentifier] autorelease]; 
     annotationView.canShowCallout = YES; 
     annotationView.image = [UIImage imageNamed:[NSString stringWithFormat:@"townhouse.png"]]; 
     UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
     [rightButton addTarget:self action:@selector(writeSomething:) forControlEvents:UIControlEventTouchUpInside]; 
     [rightButton setTitle:annotation.title forState:UIControlStateNormal]; 
     annotationView.rightCalloutAccessoryView = rightButton; 
     annotationView.canShowCallout = YES; 
     annotationView.draggable = YES; 
     return annotationView; 
    } 
    return nil; 
} 

任何幫助都將不勝感激!

/馬庫斯

回答

1

馬庫斯,

使用MKAnnotationView的centerOffset屬性來移動你的自定義註解視圖。

annotationView.centerOffset = CGPointMake(xOffset, yOffest);

+0

謝謝!就是這樣! :P – Marcus