104 自定义大头针
2015-11-09 10:36
316 查看
1.每次添加一个大头针系统会调用mapview的以下代理方法:
2.默认情况下MKAnnotationView是无法显示的(设置image才能显示), 如果想自定义大头针可以使用MKAnnotationView的子类MKPinAnnotationView
3.MKAnnotationView设置自定义的图片:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { //如果返回nil,就相当于没有任何处理,系统会按照原有的方式进行显示 一开始定位到了之后会显示一个蓝色发光的大头针,这个大头针模型是系统的 if (![annotation isKindOfClass:[HMAnnotation class]]) { //如果是系统的不做处理 return nil; } }
2.默认情况下MKAnnotationView是无法显示的(设置image才能显示), 如果想自定义大头针可以使用MKAnnotationView的子类MKPinAnnotationView
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { static NSString *identifier = @"anno"; MKPinAnnotationView *annoView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; if (annoView == nil) { annoView = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:identifier]; // 设置大头针的颜色 annoView.pinColor = MKPinAnnotationColorPurple; // 设置大头针从天而降 annoView.animatesDrop = YES; // 设置大头针标题是否显示,默认不显示 annoView.canShowCallout = YES; // 设置大头针标题显示的偏移位 annoView.calloutOffset = CGPointMake(-50, 0); // 设置大头针左边的辅助视图 annoView.leftCalloutAccessoryView = [[UISwitch alloc] init]; // 设置大头针右边的辅助视图 annoView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeContactAdd]; } // 注意: 如果你是使用的MKPinAnnotationView创建的自定义大头针, 那么设置图片无效, //因为系统内部会做一些操作, 覆盖掉我们自己的设置,这个时候只能使用父类MKAnnotationView // 3.给大头针View设置数据 annoView.annotation = annotation; // 4.返回大头针View return annoView; }
3.MKAnnotationView设置自定义的图片:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { static NSString *identifier = @"anno"; MKAnnotationView *annoView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; if (annoView == nil) { annoView = [[MKAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:identifier]; // 设置大头针标题是否显示,默认不显示 annoView.canShowCallout = YES; // 设置大头针标题显示的偏移位 annoView.calloutOffset = CGPointMake(-50, 0); // 设置大头针左边的辅助视图 annoView.leftCalloutAccessoryView = [[UISwitch alloc] init]; // 设置大头针右边的辅助视图 annoView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeContactAdd]; } // 注意: 如果你是使用的MKPinAnnotationView创建的自定义大头针, 那么设置图片无效, //因为系统内部会做一些操作, 覆盖掉我们自己的设置,这个时候只能使用父类MKAnnotationView annoView.image = [UIImage imageNamed:@"123"]; // 3.给大头针View设置数据 annoView.annotation = annotation; // 4.返回大头针View return annoView; }
相关文章推荐
- 笔记 日常的记录
- 关于android方向传感器的使用
- IntentService 串联 按顺序执行(此次任务执行完才执行下一个任务)
- List总结
- 用jQuery做全选
- py爬虫-新浪微博爬虫(1)
- easyui 处理多行的操作基础
- Beaglebone Black(6.1)Beaglebone Black的c++开发环境Eclipse构建
- javaBean与DAO简介
- iOS ARC和MRC混编
- 调用接口传递的XML 及排查原因
- 全卸载Oracle10g 方法(转)
- request doesn't contain a multipart/form-data or multipart/mixed stream
- Cannot open the disk 'F:\centos64-final\CentOS 64-bit\CentOS 64-bit.vmdk' orone of the snapshot disk
- 11月5日全球六大国际域名解析量统计:.US持续下降
- Sum Problem
- linux中likely()和unlikely()宏
- 修复ubuntu启动项grub
- 下载excel模板
- Myeclipse xml 输入包名没提示解决办法