单击时 MKMap 注释显示视图控制器而不是弹出框

发布于 2024-08-27 10:41:18 字数 103 浏览 8 评论 0原文

是否可以在新视图控制器上显示带有地图注释的更多详细信息的视图控制器,该视图控制器弹出时返回到 MKMap 视图,并且注释仍位于该位置。我似乎无法在 SDK 文档中找到一种方法来表明它是可能的。

Is it possible to display a View controller with further details of the Map annotation on a new view controller which when popped returns back to the MKMap view with the annotations still on it at that position. I can't seem to find a way in the SDK documentation that seems to indicate that its possible.

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

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

发布评论

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

评论(2

葵雨 2024-09-03 10:41:18

如果您执行以下操作,找到了我自己的问题的答案:

您可以做的是使用观察者,因此在方法中

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation

您可以添加如下代码:

 //Add an observer for the selected-property on the MKAnnotationView. Delegate to self.
  [annotationView addObserver:self
            forKeyPath:@"selected"
               options:NSKeyValueObservingOptionNew
               context:GMAP_ANNOTATION_SELECTED];

  annotationView.annotation = annotation;
  annotationView.canShowCallout = NO;

然后创建一个观察者捕获,它将调用该方法来渲染任何视图用户单击屏幕上的注释:

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context{

  NSString *action = (NSString*)context;


  if([action isEqualToString:GMAP_ANNOTATION_SELECTED]){
    BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
    if (annotationAppeared) {
      [self showAnnotation:((AssetAnnotationView*) object).annotation];
    }
    else {
      //NSLog(@"annotation deselected %@", ((AssetAnnotationView*) object).annotation.title);
      //[self hideAnnotation];
    }
  }
}

然后使用显示模式视图或任何您想要的内容的方法:

- (void)showAnnotation:(AssetAnnotationView*)annotation {

  UINavigationController *aNavController = [[UINavigationController alloc] initWithRootViewController:self.assetInfoViewController];
    aNavController.navigationBar.barStyle = UIBarStyleBlack;

  [self presentModalViewController:aNavController animated:YES];
  [aNavController release];

}

在 viewWillAppear 中取消选择:

NSArray *selected = [localMapView selectedAnnotations];
for(选定的 id 注释) {
[localMapView deselectAnnotation:注释动画:NO];
}

Found the answer to my own question if you do the following:

What you can do is use an observer instead so in the

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation

method you can add the code like this:

 //Add an observer for the selected-property on the MKAnnotationView. Delegate to self.
  [annotationView addObserver:self
            forKeyPath:@"selected"
               options:NSKeyValueObservingOptionNew
               context:GMAP_ANNOTATION_SELECTED];

  annotationView.annotation = annotation;
  annotationView.canShowCallout = NO;

then create an observer catch which will call the method to render whatever view when the user clicks the annotation on the screen:

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context{

  NSString *action = (NSString*)context;


  if([action isEqualToString:GMAP_ANNOTATION_SELECTED]){
    BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
    if (annotationAppeared) {
      [self showAnnotation:((AssetAnnotationView*) object).annotation];
    }
    else {
      //NSLog(@"annotation deselected %@", ((AssetAnnotationView*) object).annotation.title);
      //[self hideAnnotation];
    }
  }
}

then have your method which displays a modal view or whatever you want:

- (void)showAnnotation:(AssetAnnotationView*)annotation {

  UINavigationController *aNavController = [[UINavigationController alloc] initWithRootViewController:self.assetInfoViewController];
    aNavController.navigationBar.barStyle = UIBarStyleBlack;

  [self presentModalViewController:aNavController animated:YES];
  [aNavController release];

}

Unselect in viewWillAppear:

NSArray *selected = [localMapView selectedAnnotations];
for(id annotation in selected) {
[localMapView deselectAnnotation:annotation animated:NO];
}

如果没有你 2024-09-03 10:41:18

您还可以为您创建的每个注释使用标签。对我有用。

You can also use a tag for every annotation you create. Works for me.

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