2012-05-08 189 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