自动“canShowCallOut”注释 iPhone

发布于 2024-08-26 10:13:18 字数 53 浏览 6 评论 0原文

我可以通过什么方式调用自动打开注释(带有标题、副标题等)的函数,而不是触摸地图视图上的注释?

In which way could I call the function that automatically opens my annotation (with title, subtitle, etc), rather than to touch on the annotation on the mapview?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉城凉梦凉人心 2024-09-02 10:13:18

实现 MKMapViewDelegate 委托;

实现- (MKAnnotationView *)mapView: (MKMapView *)mapView_viewForAnnotation:(id)annotation_;;例如,如下所示:

    - (MKAnnotationView *) mapView: (MKMapView *) mapView_ viewForAnnotation: (id <MKAnnotation>) annotation_ {

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"YourPinId"];
    if (pin == nil) {
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation_ reuseIdentifier: @"YourPinId"] autorelease];
    }
    else {
        pin.annotation = annotation_;
    }
    pin.pinColor = MKPinAnnotationColorRed;
    [pin setCanShowCallout:YES];
    pin.animatesDrop = YES;
    return pin;
}

地图加载完成后显示图钉:

- (void) dropPin {
    [mapView addAnnotation:self.annotation];
    [mapView selectAnnotation:self.annotation animated:YES];        
}

- (void) mapViewDidFinishLoadingMap: (MKMapView *) mapView_ {
    // if done loading, show the call out
    [self performSelector:@selector(dropPin) withObject:nil afterDelay:0.3];
}

此代码有一个名为注释的属性,它实现了 MKAnnotation。另外,它也会制作针掉落的动画,但它应该是相当不言自明的。

HTH。

Implement MKMapViewDelegate delegate;

Implement - (MKAnnotationView *) mapView: (MKMapView *) mapView_ viewForAnnotation: (id <MKAnnotation>) annotation_;; for example like this:

    - (MKAnnotationView *) mapView: (MKMapView *) mapView_ viewForAnnotation: (id <MKAnnotation>) annotation_ {

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"YourPinId"];
    if (pin == nil) {
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation_ reuseIdentifier: @"YourPinId"] autorelease];
    }
    else {
        pin.annotation = annotation_;
    }
    pin.pinColor = MKPinAnnotationColorRed;
    [pin setCanShowCallout:YES];
    pin.animatesDrop = YES;
    return pin;
}

Show the pin after the map has finished loading:

- (void) dropPin {
    [mapView addAnnotation:self.annotation];
    [mapView selectAnnotation:self.annotation animated:YES];        
}

- (void) mapViewDidFinishLoadingMap: (MKMapView *) mapView_ {
    // if done loading, show the call out
    [self performSelector:@selector(dropPin) withObject:nil afterDelay:0.3];
}

This code has a property called annotation which implements MKAnnotation. Also, it animates the pin drop too, but it should be fairly self-explaining.

HTH.

残龙傲雪 2024-09-02 10:13:18

阿方斯回答了这个问题,但如果您正在寻找自动打开标注的确切内容,那就是这部分:

[mapView selectAnnotation:annotation animated:YES]; 

Alfons answered the question but if you are looking for what exactly automatically opens the callout, it's this part:

[mapView selectAnnotation:annotation animated:YES]; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文