十三年专注于网站建设与互联网应用开发,低调、有情怀的网络应用服务商!
南昌百恒科技微信公众号 扫一扫关注
tel-icon全国服务热线:400-680-9298,0791-88117053
扫一扫关注百恒科技微信公众号

IOS开发之地图视图中的可重用对象

百恒科技 2019-01-23 14:46:53 2648
       在开发地图应用时,也有一个可重用对象MKPinAnnotationView,它是在地图上的一个标注。使用地图视图的dequeueReusableAnnotationViewWithIdentifier:方法,可以获得MKPinAnnotationView对象。如果没有可重用的MKPinAnnotationView对象,则使用initWithAnnotation:reuseIdentifier:构造器创建。其模式代码如下:

       func mapView(mapView: MKMapView!,
       viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {

       var annotationView = self.mapView
       .dequeueReusableAnnotationViewWithIdentifier("PIN_ANNOTATION")
       as? MKPinAnnotationView

       if annotationView == nil {
       annotationView = MKPinAnnotationView(annotation: annotation,
       reuseIdentifier: "PIN_ANNOTATION")
       }
       annotationView!.pinColor = MKPinAnnotationColor.Purple
       annotationView!.animatesDrop = true 

       annotationView!.canShowCallout = true
       return annotationView!
      } 

       - (MKAnnotationView *) mapView:(MKMapView *)theMapView
       viewForAnnotation:(id ) annotation {

       MKPinAnnotationView *annotationView
       = (MKPinAnnotationView *)[self.mapView
       dequeueReusableAnnotationViewWithIdentifier:@"PIN_ANNOTATION"];
       if(annotationView == nil) {
       annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
       reuseIdentifier:@"PIN_ANNOTATION"];
       }

       annotationView.pinColor = MKPinAnnotationColorPurple;
       annotationView.animatesDrop = YES; 

       annotationView.canShowCallout = YES;
       return annotationView;
       }

       以上代码是地图视图中常用的处理方式,希望对大家有所帮助。如果还有哪些不明白的地方,可随时来电咨询。本公司专注于南昌APP开发等方面的服务,如有需要,我们将随时为您效劳。
400-680-9298,0791-88117053
扫一扫关注百恒网络微信公众号

欢迎您的光顾,我们将竭诚为您服务×

售前咨询 售前咨询
 
售前咨询 售前咨询
 
售前咨询 售前咨询
 
售前咨询 售前咨询
 
售前咨询 售前咨询
 
售后服务 售后服务
 
备案专线 备案专线
 
售后服务 售后服务
 
×