简体   繁体   中英

custom Callout view not displaying center of the map

+ (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

While click on annotation, call this method and pass your coordinate.

-(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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM