百恒网络
IOS开发之地图视图中的可重用对象
  • 百恒服务
  • APP开发
  • 网页案例
  • 网页知识
  • 关于我们
  • 联系我们
  • IOS开发之地图视图中的可重用对象

    2019-01-23 14:46:53 2872
           在开发地图应用时,也有一个可重用对象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开发等方面的服务,如有需要,我们将随时为您效劳。
    展开分享
    服务
    案例
    首页
    动态
    联系
    咨询