the*_*ott 5 objective-c mkmapview mkannotation
我有一个mapview.我已经实现了didAddAnnotationViews来显示我的引脚的自定义淡入淡出动画.
将引脚添加到映射时会成功调用此方法,但在删除引脚时则不会.我在文档中找不到等效的功能.是否有另一种方法可以为特定引脚实现自定义淡出动画?
我用以下方法为MKMapView创建了类别
- (void)removeAnnotation:(id<MKAnnotation>)annotation animated:(BOOL)shouldAnimate;
- (void)removeAnnotations:(NSArray *)annotations animated:(BOOL)shouldAnimate;
Run Code Online (Sandbox Code Playgroud)
你可以打电话而不是打电话
- (void)removeAnnotation:(id<MKAnnotation>)annotation;
- (void)removeAnnotations:(NSArray *)annotations;
Run Code Online (Sandbox Code Playgroud)
这是实施:
- (void)removeAnnotation:(id<MKAnnotation>)annotation animated:(BOOL)shouldAnimate {
if (!shouldAnimate)
[self removeAnnotation:annotation];
else {
MKAnnotationView *annotationView = [self viewForAnnotation:annotation];
CGRect endFrame = annotationView.frame;
endFrame = CGRectMake(
annotationView.frame.origin.x,
annotationView.frame.origin.y - self.bounds.size.height,
annotationView.frame.size.width,
annotationView.frame.size.height);
[UIView animateWithDuration:0.3
delay:0.0f
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
annotationView.frame = endFrame;
}
completion:^(BOOL finished) {
[self removeAnnotation:annotation];
}];
}
}
- (void)removeAnnotations:(NSArray *)annotations animated:(BOOL)shouldAnimate {
if (!shouldAnimate)
[self removeAnnotations:annotations];
else {
NSTimeInterval delay = 0.0;
for (id<MKAnnotation> annotation in annotations) {
MKAnnotationView *annotationView = [self viewForAnnotation:annotation];
CGRect endFrame = annotationView.frame;
endFrame = CGRectMake(
annotationView.frame.origin.x,
annotationView.frame.origin.y - self.bounds.size.height,
annotationView.frame.size.width,
annotationView.frame.size.height);
[UIView animateWithDuration:0.3
delay:delay
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
annotationView.frame = endFrame;
}
completion:^(BOOL finished) {
[self removeAnnotation:annotation];
}];
delay += 0.05;
}
}
}
Run Code Online (Sandbox Code Playgroud)
没有用于删除注释的委托方法,但您可以通过以下方式实现动画效果:
当您想要删除注释时,首先用动画淡出其视图,并在动画完成时删除注释。您的代码可能如下所示:
[UIView animateWithDuration:0.5f animations:^(void){
annotationView.alpha = 0.0f;
}
completion:^(BOOL finished){
[mapView removeAnnotation:annotation];
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1097 次 |
| 最近记录: |