[关闭]
@fiy-fish 2016-10-12T01:11:25.000000Z 字数 10026 阅读 2773

iOS原生地图 MKMapView 库翻译

iOS地图



MKMapView


@interface MKMapView (OverlaysAPI)

  1. typedef NS_ENUM(NSInteger, MKOverlayLevel) {
  2. MKOverlayLevelAboveRoads = 0, //覆盖物位于道路之上
  3. MKOverlayLevelAboveLabels//覆盖物位于标签之上
  4. } NS_ENUM_AVAILABLE(10_9, 7_0) __TVOS_AVAILABLE(9_2) __WATCHOS_PROHIBITED;
  1. - (void)addOverlay:(id <MKOverlay>)overlay level:(MKOverlayLevel)level NS_AVAILABLE(10_9, 7_0);
  2. - (void)addOverlays:(NSArray<id<MKOverlay>> *)overlays level:(MKOverlayLevel)level NS_AVAILABLE(10_9, 7_0);
  3. - (void)removeOverlay:(id <MKOverlay>)overlay NS_AVAILABLE(10_9, 4_0);
  4. - (void)removeOverlays:(NSArray<id<MKOverlay>> *)overlays NS_AVAILABLE(10_9, 4_0);
  5. - (void)insertOverlay:(id <MKOverlay>)overlay atIndex:(NSUInteger)index level:(MKOverlayLevel)level NS_AVAILABLE(10_9, 7_0);
  6. - (void)insertOverlay:(id <MKOverlay>)overlay aboveOverlay:(id <MKOverlay>)sibling NS_AVAILABLE(10_9, 4_0);
  7. - (void)insertOverlay:(id <MKOverlay>)overlay belowOverlay:(id <MKOverlay>)sibling NS_AVAILABLE(10_9, 4_0);
  8. - (void)exchangeOverlay:(id <MKOverlay>)overlay1 withOverlay:(id <MKOverlay>)overlay2 NS_AVAILABLE(10_9, 7_0);

  1. @property (nonatomic, readonly) NSArray<id<MKOverlay>> *overlays NS_AVAILABLE(10_9, 4_0);//地图上所有的覆盖物
  2. - (NSArray<id<MKOverlay>> *)overlaysInLevel:(MKOverlayLevel)level NS_AVAILABLE(10_9, 7_0);//根据不同的覆盖物类型获取 不同的覆盖物集合
  3. // Current renderer for overlay; returns nil if the overlay is not shown.
  4. - (nullable MKOverlayRenderer *)rendererForOverlay:(id <MKOverlay>)overlay NS_AVAILABLE(10_9, 7_0);
  5. //当 覆盖物还没有展示在屏幕上时,返回nil
  6. //根据覆盖物返回 渲染器, 额,看了下,渲染器这个东西貌似很屌的感觉

  1. #if TARGET_OS_IPHONE
  2. // Currently displayed view for overlay; returns nil if the view has not been created yet.
  3. // Prefer using MKOverlayRenderer and -rendererForOverlay.
  4. //返回覆盖物view
  5. - (MKOverlayView *)viewForOverlay:(id <MKOverlay>)overlay NS_DEPRECATED_IOS(4_0, 7_0) __TVOS_PROHIBITED;
  6. #endif
  7. // These methods operate implicitly on overlays in MKOverlayLevelAboveLabels and may be deprecated in a future release in favor of the methods that specify the level.
  8. //默认添加MKOverlayLevelAboveLabels 类型的覆盖物,苹果不建议用这个方法
  9. - (void)addOverlay:(id <MKOverlay>)overlay NS_AVAILABLE(10_9, 4_0);
  10. //添加多个覆盖物
  11. - (void)addOverlays:(NSArray<id<MKOverlay>> *)overlays NS_AVAILABLE(10_9, 4_0);
  12. - (void)insertOverlay:(id <MKOverlay>)overlay atIndex:(NSUInteger)index NS_AVAILABLE(10_9, 4_0);
  13. - (void)exchangeOverlayAtIndex:(NSUInteger)index1 withOverlayAtIndex:(NSUInteger)index2 NS_AVAILABLE(10_9, 4_0);

@protocol MKMapViewDelegate

  1. //地图显示区域将要改变
  2. - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated;
  3. //地图显示区域已经改变
  4. - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated;
  5. //地图将要加载
  6. - (void)mapViewWillStartLoadingMap:(MKMapView *)mapView;
  7. //地图已经加载完毕
  8. - (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView;
  9. //地图加载失败
  10. - (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error;
  11. //开始渲染地图元素
  12. - (void)mapViewWillStartRenderingMap:(MKMapView *)mapView NS_AVAILABLE(10_9, 7_0);
  13. //结束渲染地图元素
  14. - (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered NS_AVAILABLE(10_9, 7_0);
  15. // mapView:viewForAnnotation: provides the view for each annotation.
  16. // This method may be called for all or some of the added annotations.
  17. // For MapKit provided annotations (eg. MKUserLocation) return nil to use the MapKit provided annotation view.
  18. //当使用系统提供的annotation 时,返回nil
  19. //下面的方法只要用于自定义的annotation
  20. //根据annotation 在地图上展示标注view
  21. - (nullable MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;
  22. // mapView:didAddAnnotationViews: is called after the annotation views have been added and positioned in the map.
  23. // The delegate can implement this method to animate the adding of the annotations views.
  24. // Use the current positions of the annotation views as the destinations of the animation.
  25. //在这个方法中给 标注view添加 展示动画
  26. - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray<MKAnnotationView *> *)views;
  27. #if TARGET_OS_IPHONE
  28. // mapView:annotationView:calloutAccessoryControlTapped: is called when the user taps on left & right callout accessory UIControls.
  29. //这个方法中,当用户点击了标注view 左边或者右边的view(具有点击事件,要提前添加)时,调用事件方法。
  30. - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control __TVOS_PROHIBITED;
  31. #endif
  32. //点击 弹出标注view时的代理
  33. - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view NS_AVAILABLE(10_9, 4_0);
  34. //弹出的 标注view收回的时候 调用
  35. - (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view NS_AVAILABLE(10_9, 4_0);
  36. //将要开始定位用户位置前的方法
  37. - (void)mapViewWillStartLocatingUser:(MKMapView *)mapView NS_AVAILABLE(10_9, 4_0);
  38. //用户位置定位结束 后
  39. - (void)mapViewDidStopLocatingUser:(MKMapView *)mapView NS_AVAILABLE(10_9, 4_0);
  40. //更新用户位置
  41. - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation NS_AVAILABLE(10_9, 4_0);
  42. //用户位置定位失败
  43. - (void)mapView:(MKMapView *)mapView didFailToLocateUserWithError:(NSError *)error NS_AVAILABLE(10_9, 4_0);
  44. //标注view 被拖拽的时候调用
  45. - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view didChangeDragState:(MKAnnotationViewDragState)newState
  46. fromOldState:(MKAnnotationViewDragState)oldState NS_AVAILABLE(10_9, 4_0) __TVOS_PROHIBITED;
  47. #if TARGET_OS_IPHONE
  48. //用户定位模式 更改时的方法
  49. - (void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated NS_AVAILABLE(NA, 5_0);
  50. #endif
  51. //给地图添加遮盖物时候,必须调用 [使用方法](http://www.wtoutiao.com/p/3d49ULc.html)
  52. - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay NS_AVAILABLE(10_9, 7_0);
  53. //添加多个遮盖物结束后调用
  54. - (void)mapView:(MKMapView *)mapView didAddOverlayRenderers:(NSArray<MKOverlayRenderer *> *)renderers NS_AVAILABLE(10_9, 7_0);
  55. #if TARGET_OS_IPHONE
  56. // Prefer -mapView:rendererForOverlay:
  57. // 获取覆盖物
  58. - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay NS_DEPRECATED_IOS(4_0, 7_0) __TVOS_PROHIBITED;
  59. // Called after the provided overlay views have been added and positioned in the map.
  60. // Prefer -mapView:didAddOverlayRenderers:
  61. - (void)mapView:(MKMapView *)mapView didAddOverlayViews:(NSArray *)overlayViews NS_DEPRECATED_IOS(4_0, 7_0) __TVOS_PROHIBITED;
  62. #endif
  63. @end
  64. NS_ASSUME_NONNULL_END
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注