Ios MKMapView添加注释并在一段时间后将其删除
我有一个MKMapView,并在其中添加了一些注释。我想在添加注释一段时间后逐个删除注释。我需要每个注释都有自己的寿命。可能吗?如何实现这一点?您的最佳选择是使用Ios MKMapView添加注释并在一段时间后将其删除,ios,objective-c,mkmapview,mkpointannotation,Ios,Objective C,Mkmapview,Mkpointannotation,我有一个MKMapView,并在其中添加了一些注释。我想在添加注释一段时间后逐个删除注释。我需要每个注释都有自己的寿命。可能吗?如何实现这一点?您的最佳选择是使用-(void)removeAnnotations:(NSArray*)注释从MKMapView中删除注释 只需将注释保存在某个位置,例如带有{date:annotationObject}的NSDictionary,并在需要删除时检索它 例如: //Call somewhere to delete after 2 seconds [sel
-(void)removeAnnotations:(NSArray*)注释
从MKMapView
中删除注释
只需将注释保存在某个位置,例如带有{date:annotationObject}的NSDictionary,并在需要删除时检索它
例如:
//Call somewhere to delete after 2 seconds
[self performSelector:@selector(deleteAnnotation:) withObject:annotation afterDelay:2.f]
//this function will remove the annotation from your map
-(void) deleteAnnotation:(id) object{
[self.map removeAnnotations:@[object]];
}
最好的选择是使用
-(void)从MKMapView
中删除注释:(NSArray*)注释
只需将注释保存在某个位置,例如带有{date:annotationObject}的NSDictionary,并在需要删除时检索它
例如:
//Call somewhere to delete after 2 seconds
[self performSelector:@selector(deleteAnnotation:) withObject:annotation afterDelay:2.f]
//this function will remove the annotation from your map
-(void) deleteAnnotation:(id) object{
[self.map removeAnnotations:@[object]];
}
MKMapView具有删除已添加注释的removeAnnotations
和removeAnnotations
方法
如果希望每个注释都有自己的寿命,请执行以下操作:
- 创建
AnnotationLifespanDelegate
协议,该协议使用指示寿命结束的方法,该方法将注释作为参数(例如func-dearAnnotationRIP(注释:MKAnnotation)
)
- 使用
lifespand
和lifeSpanDelegate
属性和startCountdown
方法创建自定义MKAnnotation
startCountdown
方法只需启动一个间隔等于寿命的计时器
,并调用委托上的寿命结束方法
- 在视图控制器中实现
AnnotationLifespanDelegate
方法,并在创建注释对象时,确保设置lifespance
和delegate
并在将注释添加到地图视图后立即调用注释上的startCountdown
方法
- 在“注释寿命终止”方法中,从地图中删除注释
MKMapView有removeAnnotation
和removeAnnotations
方法可以删除已经添加的注释
如果希望每个注释都有自己的寿命,请执行以下操作:
- 创建
AnnotationLifespanDelegate
协议,该协议使用指示寿命结束的方法,该方法将注释作为参数(例如func-dearAnnotationRIP(注释:MKAnnotation)
)
- 使用
lifespand
和lifeSpanDelegate
属性和startCountdown
方法创建自定义MKAnnotation
startCountdown
方法只需启动一个间隔等于寿命的计时器
,并调用委托上的寿命结束方法
- 在视图控制器中实现
AnnotationLifespanDelegate
方法,并在创建注释对象时,确保设置lifespance
和delegate
并在将注释添加到地图视图后立即调用注释上的startCountdown
方法
- 在“注释寿命终止”方法中,从地图中删除注释