简体   繁体   English

如何隐藏MKAnnotationView?

[英]How to hide MKAnnotationView?

I have a problem hiding a MKAnnotationView after some time [4 seconds]. 我在一段时间[4秒]后隐藏MKAnnotationView遇到问题。 I have a MKMapView named mapView which shows user location with MKUserLocation and I have added a UIButtonTypeDetailDisclosure to his MKAnnotationView . 我有一个名为mapViewMKMapView ,它使用MKUserLocation显示用户位置,并且向他的MKAnnotationView添加了UIButtonTypeDetailDisclosure The MKAnnotationView automatically gets selected but I want to deselect it after some time with a NSTimer . MKAnnotationView自动被选中,但是我想在一段时间后使用NSTimer取消选择它。 I have correctly implemented the timer and the void method gets called correctly [I have checked it with a NSLog ] but I don't know what code to write in the void method to make the annotation disappear. 我已经正确实现了计时器,并且正确调用了void方法[已使用NSLog进行了检查],但是我不知道在void方法中编写什么代码以使注释消失。

this is my code: 这是我的代码:

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

Can someone help me writing the code? 有人可以帮我编写代码吗?

You need to pass your view.annotation as userInfo object and implement hideMKAnnotation as 您需要将view.annotation作为userInfo对象传递,并将hideMKAnnotation实现为

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM