zoukankan      html  css  js  c++  java
  • MKMapView自定义大头针

    如何自定义大头针

    ——设置 MKMapView 的代理

    实现下面的代理方法,返回大头针控件

    - ( MKAnnotationView *)mapView:( MKMapView *)mapView viewForAnnotation:( id< MKAnnotation >)annotation;

    根据传进来的 ( id < MKAnnotation >)annotation 参数创建并返回对应的大头针控件

    代理方法的使用注意

    如果返回 nil ,显示出来的大头针就采取系统的默认样式

    标识用户位置的蓝色发光圆点,它也是一个大头针,当显示这个大头针时,也会调用代理方法

    因此,需要在代理方法中分清楚 ( id < MKAnnotation >)annotation 参数代表自定义的大头针还是蓝色发光圆点

     1 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
     2 {
     3     // 判断annotation的类型
     4     if (![annotation isKindOfClass:[MJTuangouAnnotation class]]) return nil;
     5     
     6     // 创建MKAnnotationView
     7     static NSString *ID = @"tuangou";
     8     MKAnnotationView *annoView = [mapView dequeueReusableAnnotationViewWithIdentifier:ID];
     9     if (annoView == nil) {
    10         annoView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:ID];
    11         annoView.canShowCallout = YES;
    12     }
    13     // 传递模型数据
    14     annoView.annotation = annotation;
    15     
    16     // 设置图片
    17         MJTuangouAnnotation *tuangouAnnotation = annotation;
    18     annoView.image = [UIImage imageNamed:tuangouAnnotation.icon];
    19     
    20     return annoView;
    21 }

    MKAnnotationView

    地图上的大头针控件是 MKAnnotationView

    MKAnnotationView 的属性

     1 @property (nonatomic, strong) id <MKAnnotation> annotation;
     2 大头针模型
     3 
     4 @property (nonatomic, strong) UIImage *image;
     5 显示的图片
     6 
     7 @property (nonatomic) BOOL canShowCallout;
     8 是否显示标注
     9 
    10 @property (nonatomic) CGPoint calloutOffset;
    11 标注的偏移量
    12 
    13 @property (strong, nonatomic) UIView *rightCalloutAccessoryView;
    14 标注右边显示什么控件
    15 
    16 @property (strong, nonatomic) UIView *leftCalloutAccessoryView;
    17 标注左边显示什么控件

    MKPinAnnotationView

    MKPinAnnotationView 是 MKAnnotationView 的子类

    MKPinAnnotationView 比 MKAnnotationView 多了 2 个属性

    1 @property (nonatomic) MKPinAnnotationColor pinColor;//大头针颜色
    2 
    3 @property (nonatomic) BOOL animatesDrop;//大头针第一次显示时是否从天而降

  • 相关阅读:
    Python基础练习
    AngularJS学习之旅—AngularJS 过滤器(七)
    AngularJS学习之旅—AngularJS 控制器(六)
    AngularJS学习之旅—AngularJS Scope作用域(五)
    AngularJS学习之旅—AngularJS 模型(四)
    AngularJS学习之旅—AngularJS 指令(三)
    AngularJS学习之旅—AngularJS 表达式(二)
    AngularJS学习之旅—AngularJS 简介(一)
    SQL Server排名或排序的函数
    Asp.net导出Excel/Csv文本格式数据
  • 原文地址:https://www.cnblogs.com/ranger-jlu/p/4301312.html
Copyright © 2011-2022 走看看