0

annotationView 气泡大小太小了 10 次中有 9 次。[self.mapView selectAnnotation:self.selectedVenue animated:YES];选择一行时,我调用以显示注释视图。无论我设置animated: YES还是NO它仍然显示错误的大小。但是,如果我将地图视图高度的大小增加到至少 200 像素,一切看起来都很好,除了地图视图对于 3.5 英寸屏幕来说太大了。

我希望地图视图是这个大小和注释气泡以正确覆盖标题和副标题。

图片:https ://dl.dropboxusercontent.com/u/5105730/anno.png

这是我创建注释视图的方法。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{

if ([annotation isKindOfClass:[FSVenue class]]) {
    static NSString *PlaceAnnotationIdentifier = @"Place Identifier";

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:PlaceAnnotationIdentifier];

    if (annotationView == nil)  {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:PlaceAnnotationIdentifier];
    }

    annotationView.annotation = annotation;

    UIButton *calloutButton = [UIButton buttonWithType:(UIButtonTypeContactAdd)];
    calloutButton.tintColor = self.themeColor;

    annotationView.enabled = YES;
    annotationView.pinColor = MKPinAnnotationColorGreen;
    annotationView.canShowCallout = YES;
    annotationView.rightCalloutAccessoryView = calloutButton;
    annotationView.animatesDrop = YES;

    return annotationView;
}

return nil;

}

4

1 回答 1

0

添加这样的注释后,您必须缩放地图视图的可见矩形。

[self.yourMapview addAnnotations:self.yourAnnotationsArray];
[self zoomToAnnotations];

像这样添加注释后调用此方法

-(void)zoomToAnnotations{

    MKMapRect zoomRect = MKMapRectNull;

    for (_yourAnnotation in self.yourMapView.annotations) {
        MKMapPoint annotationPoint = MKMapPointForCoordinate(_yourAnnotation.coordinate);
        MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0.1, 0.1);
        if (MKMapRectIsNull(zoomRect)) {
            zoomRect = pointRect;
        }else{
            zoomRect = MKMapRectUnion(zoomRect, pointRect);
        }
    }
    if (zoomRect.size.width == 0.10) /* for single annotation available in map */
    {
        zoomRect = MKMapRectMake(zoomRect.origin.x, zoomRect.origin.y, 100000, 100000);
    }

    [[self yourMapView] setVisibleMapRect:zoomRect edgePadding:UIEdgeInsetsMake(50, 50, 50, 50) animated:YES];

}
于 2013-11-14T15:04:37.237 回答