重绘大头针视图,大头针渲染时会调用地图代理的方法,我们可以重写这个方法进行大头针的重绘,来更改其颜色: -(MKAnnotationView *)mapView:(MKMapView *)mapView MKAnnotationView是标注的视图类,一会我们通过它来自定义我们自己的标注,先来看MKPinAnnotationView这个类,这个类继承于MKAnnotationView,是一个大头针视图类 *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{ MKAnnotationView * view = [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"annotation"]; / 四、标注视图类MKAnnotationView的其他常用属性解读 @property (nonatomic) CGPoint centerOffset; 视图中心的偏移量 @property (nonatomic
- (nullable MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate; ---- 大头针view显示类:MKPinAnnotationView 继承于 MKAnnotationView 1.MKAnnotationView :默认image属性没有赋值,可以完全自定义 (1)设置大头针可以被点击,用于显示附属视图、标题、子标题等,自定义时默认为NO,想要大头针被点击注意开启 @property ),也可以直接调用封装好的自定义大头针view,且不必给大头针view设置大头针模型,系统会自动调用view的set方法进行设置 - (MKAnnotationView *)mapView:(MKMapView *> *)views{ for (MKAnnotationView *annoView in views) { // 不要将系统定位的大头针设置了动画效果 if
MKMapViewDelegate> @property(nonatomic,strong)MKMapView *mapView;//添加一个MApView @property(nonatomic,strong)MKAnnotationView mapView.delegate = self; [self.view addSubview:_mapView]; //对annotation 的设置 _annotationView = [[MKAnnotationView "石家庄"; [self.mapView addAnnotation:annotation]; } #pragma mark-mapView的代理方法-显示标识的方法 -(MKAnnotationView
地图上有几个大头针就调用几次) /* * @param mapView 地图 * @param annotation 大头针模型 * * @return 大头针的view */ - (MKAnnotationView return nil; 创建大头针,给大头针附模型属性 类型 tableViewCell static NSString *identifier = @"anno"; // 1.从缓存池中取 MKAnnotationView UIButtonTypeContactAdd]; } // 设置大头针的图片 annoView.image = [UIImage imageNamed:@"category_4"]; 创建另一中大头针 MKAnnotationView UIImage imageNamed:@"category_4"]; // 4.返回大头针View return annoView; 自定义AnnotationView 类型自定义Cell 继承MKAnnotationView // 每次添加大头针就会调用此方法 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation
init]; annotation.coordinate = coordinate; [self.map addAnnotation:annotation]; } -(MKAnnotationView 实现效果 五、添加自定义标注 实现功能:在前面的基础上,自定义标注的样式 代码:只需要更改上面的代理方法即可 -(MKAnnotationView *)mapView:(MKMapView *) annotation isKindOfClass:[MKUserLocation class]]) { return nil; } //1.从重用池取MKAnnotationView MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"abc"]; //2.没有的时候创建 if(annotationView == nil) { annotationView = [[MKAnnotationView
关于导入百度地图SDK出现的问题(一) ---- 原帖地址 1.MKAnnotationView和MKPinAnnotationView的区别. 如果想创建以静态图片作为大头针图片的话,可以通过创建MKAnnotationView是实例。
这一接口 上面的downloaderOperation的代理 SDWebImagePrefetcher 低优先级情况下预先下载图片,对SDWebImageViewManager进行简单封装 很少用 MKAnnotationView +WebCache – 为MKAnnotationView异步加载图片 UIButton+WebCache 为UIButton异步加载图片 UIImage+GIF 将Image data转换成指定格式图片 HighlightedWebCache 为UIImageView异步加载图片 UIImageView+WebCache 为UIImageView异步加载图片 UIView+WebCacheOperation 保存当前MKAnnotationView
removeAnnotations:(NSArray *)annotations; 移除一组标注 @property (nonatomic, readonly) NSArray *annotations; 获取所有标注数组 - (MKAnnotationView *)viewForAnnotation:(id <MKAnnotation>)annotation; 获取标注的视图 - (MKAnnotationView *)dequeueReusableAnnotationViewWithIdentifier 地图加载完成时执行的方法 - (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error; 地图加载失败时执行的方法 - (MKAnnotationView didAddAnnotationViews:(NSArray *)views; 标注添加完成后调用的方法 - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view; 选中标注时调用的方法 - (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView
pragma mark - MKMapViewDelegate //点击大头针 - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView 重置汽车原来的颜色 NSArray *array = [mapView annotations]; for (MyAnnotation *an in array) { MKAnnotationView ) animated:YES]; } } //没有选中大头针 - (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView 重置汽车原来的颜色 NSArray *array = [mapView annotations]; for (MyAnnotation *an in array) { MKAnnotationView = YES; // 设置大头针是否有下落动画 pinView.animatesDrop = YES; return pinView; } //自定义大头针 - (MKAnnotationView
initWithCoordinate:coord andTitle:titile]; //添加标注 [self.mapView addAnnotation:myPoint]; } - (MKAnnotationView placemarkIdentifier = @"PointAnnotation"; if ([annotation isKindOfClass:[MSCarPoint class]]){ MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:placemarkIdentifier - (nullable MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation // MARK: - map delegate func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView
分类 MKPinAnnotationView:系统自带的标注,继承于 MKAnnotationView,形状跟棒棒糖类似,可以设置糖的颜色,和显示的时候是否有动画效果 (Swift 不推荐使用)。 MKAnnotationView:可以用指定的图片作为标注的样式,但显示的时候没有动画效果,如果没有指定图片会什么都不显示(自定义时使用)。 ViewController: MKMapViewDelegate { func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView ViewController: MKMapViewDelegate { func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView withIdentifier: identifier) // 判空 if annotationView == nil { annotationView = MKAnnotationView
SDWebImage 提供了 UIImageView、UIButton 、MKAnnotationView 的图片下载分类,只要一行代码就可以实现图片异步下载和缓存功能。 SDWebImage 特点 提供 UIImageView, UIButton, MKAnnotationView 的分类,用来显示网络图片,以及缓存管理 异步下载图片 异步缓存(内存+磁盘),并且自动管理缓存有效性
. - (MKAnnotationView *)viewForAnnotation:(id )annotation; // Used by the delegate to acquire an already allocated annotation view, in line of allocating a new one. - (MKAnnotationView *)dequeueReusableAnnotationViewWithIdentifier MKUserLocation) return nil to use the MapKit provided annotation view. - (MKAnnotationView *)mapView: on left & right callout accessory UIControls. - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view NS_AVAILABLE(10_9, 4_0); - (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView
为方便起见,我们为UI元素例如UIImageView,UIButton,MKAnnotationView等类添加了categories。 ? 1. 特征 ---- 为UIImageView,UIButton,MKAnnotationView的Categories添加了有关网络图像和高速缓存管理的Categories 异步图像下载器 异步内存+磁盘图像缓存
SDWI 也提供了 UIButton+WebCache 和 MKAnnotationView+WebCache,方便使用。 SDWebImagePrefetcher 可以预先下载图片,方便后续使用。
(定位) 2、CLGeocoder (地理编码和反地理编码) 3、CLPlacemark、CLLocation、CLLocationCoordinate2D (几个位置类)和 MKAnnotationView MKMapView 有个 MKMapViewDelegate 代理方法,它具体的方法可以点进这个协议去看,里面有个方法是 - (nullable MKAnnotationView *)mapView:( MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation; 它返回的是一个 MKAnnotationView ,
focusMapTo:placemark.location.coordinate]; }]; [searchBar endEditing:YES]; } #pragma mark - 返回大头针 - (MKAnnotationView WWWAnnotationViewDelegate <NSObject> - (void)changedRadius:(UIButton *)button; @end @interface WWAnnotationView : MKAnnotationView
16、SDWI 也提供了 UIButton+WebCache 和 MKAnnotationView+WebCache,方便使用。 除了扩展UIImageView外,SDWebImage还扩展了UIView,UIButton,MKAnnotationView等视图类,具体可以参考源码,除了可以使用扩展的方法下载图片,同时也可以使用SDWebImageManager
SDWI 也提供了 UIButton+WebCache 和 MKAnnotationView+WebCache,方便使用。 SDWebImagePrefetcher 可以预先下载图片,方便后续使用。
renderer.strokeColor = [UIColor redColor]; renderer.lineWidth = 4.0; return renderer; } //标注的代理方法 -(MKAnnotationView