gpt4 book ai didi

objective-c - 相当于 "didAddAnnotationViews"用于移除引脚?

转载 作者:太空狗 更新时间:2023-10-30 03:50:15 26 4
gpt4 key购买 nike

我有一个 map View 。我已经实现了 didAddAnnotationViews 来为我的图钉显示自定义淡入淡出动画。

当大头针被添加到 map 时调用成功,但当大头针被移除时则不会。我在文档中找不到等效的函数。是否有另一种方法可以为特定引脚实现自定义淡出动画?

最佳答案

我已经使用以下方法为 MKMapView 创建了类别

- (void)removeAnnotation:(id<MKAnnotation>)annotation animated:(BOOL)shouldAnimate;
- (void)removeAnnotations:(NSArray *)annotations animated:(BOOL)shouldAnimate;

你可以调用而不是调用

- (void)removeAnnotation:(id<MKAnnotation>)annotation;
- (void)removeAnnotations:(NSArray *)annotations;

实现如下:

- (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;
}
}
}

关于objective-c - 相当于 "didAddAnnotationViews"用于移除引脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6726621/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com