gpt4 book ai didi

ios - 如何隐藏 MKAnnotationView?

转载 作者:行者123 更新时间:2023-11-29 10:48:42 29 4
gpt4 key购买 nike

我在一段时间 [4 秒] 后隐藏 MKAnnotationView 时遇到问题。我有一个名为 ma​​pViewMKMapView,它使用 MKUserLocation 显示用户位置,我在他的 中添加了一个 UIButtonTypeDetailDisclosure >MKAnnotationViewMKAnnotationView 会自动被选中,但我想在一段时间后使用 NSTimer 取消选择它。我已经正确地实现了计时器并且 void 方法被正确调用 [我已经用 NSLog 进行了检查] 但我不知道要在 void 方法中编写什么代码才能使注释消失。

这是我的代码:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
for (MKAnnotationView* view in views)
{
if ([view.annotation isKindOfClass:[MKUserLocation class]])
{
view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

[self.mapView selectAnnotation:view.annotation animated:YES];
}

mKAnnotationHideTimer = [NSTimer scheduledTimerWithTimeInterval:4.0
target:self
selector:@selector(hideMKAnnotation:)
userInfo:nil
repeats:NO];
}
}

- (void)hideMKAnnotation:(NSArray *)views
{
// What code here?
}

有人可以帮我写代码吗?

最佳答案

您需要将 view.annotation 作为 userInfo 对象传递,并将 hideMKAnnotation 实现为

- (void)hideMKAnnotation:(NSTimer*)timer
{
id aview = timer.userInfo;
[self.mapView deselectAnnotation:aview animated:YES];
}

关于ios - 如何隐藏 MKAnnotationView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21363114/

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