使用地图须知:MKMapViewDelegate

Responding to Map Position Changes

1
2
- ( void )mapView:(MKMapView *)mapView regionWillChangeAnimated:( BOOL )animated //将要改变region时调用。如果scroll则会调用很多次
- ( void )mapView:(MKMapView *)mapView regionDidChangeAnimated:( BOOL )animated //region改变后调用。如果scroll则会调用很多次

 

Loading the Map Data

1
2
3
4
5
- ( void )mapViewWillStartLoadingMap:(MKMapView *)mapView //开始下载地图块(map tiles)时候调用
- ( void )mapViewDidFinishLoadingMap:(MKMapView *)mapView //地图下载完成块时调用
- ( void )mapViewDidFailLoadingMap:(MKMapView *)mapView withError:( NSError  *)error //地图下载出错时调用,网络问题、前一个下载未完成等
- ( void )mapViewWillStartRenderingMap:(MKMapView *)mapView //开始渲染下载的地图块时调用
- ( void )mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:( BOOL )fullyRendered //渲染结束时调用。fullyRendered:是否成功渲染

 

Tracking the User Location

1
2
3
4
5
- ( void )mapViewWillStartLocatingUser:(MKMapView *)mapView //将要获取用户位置。showsUserLocation设为YES后调用
- ( void )mapViewDidStopLocatingUser:(MKMapView *)mapView //showsUserLocation设为NO后调用
- ( void )mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation //用户位置更新或者Head更新时调用。后台运行不会调用
- ( void )mapView:(MKMapView *)mapView didFailToLocateUserWithError:( NSError  *)error //尝试锁定用户位置失败
- ( void )mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:( BOOL )animated //改变UserTrackingMode

didUpdateUserLocation:This method is not called if the application is currently running in the background. If you want to receive location updates while running in the background, you must use the Core Location framework.

 

Managing Annotation Views

1
2
3
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:( id <MKAnnotation>)annotation //设置annotation的View
- ( void )mapView:(MKMapView *)mapView didAddAnnotationViews:( NSArray  *)views //地图上加上了annotationViews后调用
- ( void )mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control //Tap a anotationView's accessory button后调用

If the object in the annotation parameter is an instance of the MKUserLocation class, you can provide a custom view to denote the user’s location. To display the user’s location using the default system view, return nil.

If you do not implement this method, or if you return nil from your implementation for annotations other than the user location annotation, the map view uses a standard pin annotation view.

 

Dragging an Annotation View

1
2
- ( void )mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView
didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState<br> //移动annotation位置时调用。state为宏,表示几个状态。是否能移动位置在annotation中设置。

MKAnnotationViewDragStateStarting:拿起

MKAnnotationViewDragStateDragging:开始拖拽

MKAnnotationViewDragStateEnding:放下

 

Selecting Annotation Views

1
2
- ( void )mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view //选择了一个annotationView
- ( void )mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view //取消选择了一个annotationView

 

Managing the Display of Overlays

1
2
3
4
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:( id <MKOverlay>)overlay //设置overlay的渲染
- ( void )mapView:(MKMapView *)mapView didAddOverlayRenderers:( NSArray  *)renderers //地图上加上了overlayRenderers后调用
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:( id <MKOverlay>)overlay //同上面。IOS7.0后不使用
- ( void )mapView:(MKMapView *)mapView didAddOverlayViews:( NSArray  *)overlayViews //同上面。IOS7.0后不使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值