自定义标注视图不显示地图的中心

时间:2013-09-13 10:18:46

标签: iphone ios objective-c

+ (MultiRowCalloutAnnotationView *)calloutWithAnnotation:(id<MultiRowAnnotationProtocol>)annotation onCalloutAccessoryTapped:(MultiRowAccessoryTappedBlock)block {
    return [[[MultiRowCalloutAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:MultiRowCalloutReuseIdentifier onCalloutAccessoryTapped:block] autorelease];
}

- (id)initWithAnnotation:(id<MultiRowAnnotationProtocol>)annotation reuseIdentifier:(NSString *)reuseIdentifier onCalloutAccessoryTapped:(MultiRowAccessoryTappedBlock)block {
    self = [super initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentHeight = 80.0;
        _yShadowOffset = 6;
        self.offsetFromParent = CGPointMake(8, -14); //this works for MKPinAnnotationView
        self.enabled = NO;
        self.backgroundColor = [UIColor clearColor];
        self.cellInsetX = 15;
        self.cellOffsetY = 10;
        self.onCalloutAccessoryTapped = block;
        [self setTitleWithAnnotation:annotation];
        [self setCalloutCellsWithAnnotation:annotation];
    }
    return self;
}

- (id)initWithAnnotation:(id<MultiRowAnnotationProtocol>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    self = [self initWithAnnotation:annotation reuseIdentifier:reuseIdentifier onCalloutAccessoryTapped:nil];
    return self;
}

Refer image here

1 个答案:

答案 0 :(得分:1)

点击注释时,调用此方法并传递坐标。

-(void)didSelectAnnotationAtCoordinate:(CLLocationCoordinate2D)coordinate
{
    MKMapRect mapRect = [self.mapView visibleMapRect];
    MKMapPoint point = MKMapPointForCoordinate(coordinate);
    mapRect.origin.x = point.x - mapRect.size.width * 0.3;//change value
    mapRect.origin.y = point.y - mapRect.size.height * 0.70;//change value                  
    [self.mapView setVisibleMapRect:mapRect animated:YES];
}