大佬教程收集整理的这篇文章主要介绍了地图注释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; }
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,请注明来意。