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后不使用 |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步