【问题标题】:Changing CustomCallout Bubble Height in MapView - iOS在 MapView 中更改 CustomCallout 气泡高度 - iOS
【发布时间】:2016-07-28 05:54:07
【问题描述】:

我有自定义注释,它的 calloutbubble 具有高度为 200 的表格所在的视图。
但是,在标注气泡中设置它时,它不会影响标注气泡的大小
我怎样才能做到这一点?
这是我的代码

-(MKAnnotationView *)mapView:(MKMapView *)mapView1 viewForAnnotation:(id<MKAnnotation>)annotation
{
     if([annotation isKindOfClass:[CustomAnnotation class]])
    {
        CustomAnnotation *location = (CustomAnnotation *)annotation;
        MKAnnotationView   *annotation_View = [mapView1 dequeueReusableAnnotationViewWithIdentifier:@"customAnnotation"];
        if (annotation_View == nil)
        {
            annotation_View = location.annotationView;
            if ([location.title isEqualToString:@"My Spot"])
            {
                annotation_View.image = [UIImage imageNamed:@"orange.png"];
            }
            else
            {
                annotation_View.image=[UIImage imageNamed:@"ocean.png"];
            }
        }
        else
        {
            annotation_View.annotation = annotation;
        }
        [self configureDetailView:annotation_View];
        return annotation_View;
    }
    return nil;
}

-(void)configureDetailView : (MKAnnotationView*)annotationView1
{
    self.AnnotationViewForDetail.frame = CGRectMake(0, 0, 100, 200);
    annotationView1.detailCalloutAccessoryView = self.AnnotationViewForDetail;
}

【问题讨论】:

    标签: ios cllocationmanager mkannotation mkannotationview mapkitannotation


    【解决方案1】:

    请参考这个answer

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
        static NSString *identifier = @"MyAnnotationView";
    
    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        return nil;
    }
    
    MKPinAnnotationView *view = (id)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
    if (view) {
        view.annotation = annotation;
    } else {
        view = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        view.canShowCallout = true;
        view.animatesDrop = true;
    }
    view.detailCalloutAccessoryView = [self detailViewForAnnotation:annotation];
    
    return view;
    }
    
    - (UIView *)detailViewForAnnotation:(PlacemarkAnnotation *)annotation {
        UIView *view = [[UIView alloc] init];
        view.translatesAutoresizingMaskIntoConstraints = false;
    
        UILabel *label = [[UILabel alloc] init];
        label.text = annotation.placemark.name;
        label.font = [UIFont systemFontOfSize:20];
        label.translatesAutoresizingMaskIntoConstraints = false;
        label.numberOfLines = 0;
        [view addSubview:label];
    
        UIButton *button = [self yesButton];
        [view addSubview:button];
    
        NSDictionary *views = NSDictionaryOfVariableBindings(label, button);
    
        [view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[label]|" options:0 metrics:nil views:views]];
        [view addConstraint:[NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
        [view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[label]-[button]|" options:0 metrics:nil views:views]];
    
        return view;
    }
    
    - (UIButton *)yesButton {
        UIImage *image = [self yesButtonImage];
    
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.translatesAutoresizingMaskIntoConstraints = false; // use auto layout in this case
        [button setImage:image forState:UIControlStateNormal];
        [button addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventPrimaryActionTriggered];
    
        return button;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-03
      • 2021-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      相关资源
      最近更新 更多