HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了地图注释showCallout-iOS大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有问题显示注释标题,如下图所示.第一张图片非常好地表示价值;另一方面,一旦值达到三位数,则标题显示三个点,如第二幅图像所示.我想知道如何解决这个问题.任何想法都会受到欢迎!非常感谢提前,谢谢!我刚把我的代码在这里供参

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)Annotation {
   MKAnnotationView *pinView=nil;
    if(![Annotation isKindOfClass:[Annotation class]]) // Don't mess user LOCATIOn
        return nil;

    static NSString *defaultPinID = @"StandardIdentifier";
    pinView = (MKAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if (pinView == nil){
        pinView = [[MKAnnotationView alloc] initWithAnnotation:Annotation reusEIDentifier:defaultPinID];
    }

    if ([Annotation isKindOfClass:[Annotation class]]) {
        Annotation *a = (Annotation *)Annotation;

        pinView.image = [ZSPinAnnotation pinAnnotationWithColor:a.color];
        pinView.Annotation = a;
        pinView.enabled = YES;
        pinView.centerOffset=CGPointMake(6.5,-16);
        pinView.calloutOffset = CGPointMake(-11,0);

    }

    pinView.canShowCallout = YES;
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton settitle:Annotation.title forState:UIControlStateNormal];
    [pinView setrightCalloutAccessoryView:rightButton];
    pinView.leftCalloutAccessoryView = [[UIView alloc] init];
    pinView.leftCalloutAccessoryView=nil;

    return pinView;
  }

我的showCallout标题在以下代码中更新:

NSnumber *attr2=[attr valueForKey:@"ozone_level"];
Annotation.title=[NSString StringWithFormat:@"Ozone Level:%@",[attr2 stringvalue]];

解决方法

问题是标题更改时不会重新计算标注视图的布局.也许你应该为此提交错误报告.

要强制重新布局,如果标注可见,您可以以编程方式取消选择并选择注释.它不是动画,但它会改变标注的宽度:

NSnumber *attr2=[attr valueForKey:@"ozone_level"];
Annotation.title=[NSString StringWithFormat:@"Ozone Level:%@",[attr2 stringvalue]];


if ([self.mapView viewForAnnotation:Annotation] != nil) {
    NSArray *SELEctedAnnotations = self.mapView.SELEctedAnnotations;
    if ((SELEctedAnnotations != nil) && ([self.mapView.SELEctedAnnotations indexOfObject:Annotation] != NsnotFound)) {
        [self.mapView deSELEctAnnotation:Annotation animated:NO];
        [self.mapView SELEctAnnotation:Annotation animated:NO];
    }
}

您还应该删除此行,因为注释的标题仍然用作注释上的文本标签

[rightButton settitle:Annotation.title forState:UIControlStateNormal];

更新:

@detunized提供的解决方案适用于动画.您可以更好地删除并重新添加按钮视图,而不是创建不需要的UIView:

NSnumber *attr2=[attr valueForKey:@"ozone_level"];
Annotation.title=[NSString StringWithFormat:@"Ozone Level:%@",[attr2 stringvalue]];

MKAnnotationView *AnnotationView = [self.mapView viewForAnnotation:Annotation];
// The Annotation must be visible,otherwise a refresh isn't needed
if (AnnotationView != nil) {
    NSArray *SELEctedAnnotations = self.mapView.SELEctedAnnotations;
    // The Annotation must be SELEcted,otherwise a refresh isn't needed
    if ((SELEctedAnnotations != nil) && ([self.mapView.SELEctedAnnotations indexOfObject:Annotation] != NsnotFound)) {
            // Unset and re-set the right button to force relayout
            UIView *view = AnnotationView.rightCalloutAccessoryView;
            AnnotationView.rightCalloutAccessoryView = nil;
            AnnotationView.rightCalloutAccessoryView = view;
    }
}

大佬总结

以上是大佬教程为你收集整理的地图注释showCallout-iOS全部内容,希望文章能够帮你解决地图注释showCallout-iOS所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。