
- (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 neededif (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所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)