MKAnnotationView - 锁定自定义注释视图以固定位置更新

2023-12-12

更新#5我想现在是赏金时间了即使我发布了代码示例,也有 100 多次浏览,但没有人尝试。一些声望点怎么样!

更新#4这是一个非常复杂的问题,所以我创建了一个新的基于选项卡的项目,其中只包含我在这里遇到问题的应用程序部分。您可以从以下位置下载:http://www.servinitup.net/CustomCalloutAnnotation.zip请随意打开它(需要添加您自己的包标识符才能在手机上运行它)并使用它,看看是否可以让该死的标注注释随图钉一起移动!

更新#3尝试将 setAnnotation 设为教程 CalloutMapAnnotationView 的公共方法并直接调用。没有任何运气。尽管发生了一些奇怪的事情,唯一移动的是标注的小三角形部分。我无法移动整个标注。

更新#2仍然不太幸运,但现在一直在寻找以编程方式创建“捏合缩放”然后立即撤消它的方法,因此用户永远不会看到更改。希望以编程方式执行此操作将具有与手动执行相同的效果,并且标注注释将弹回其父级。有任何想法吗?

更新#1在玩完这里之后,我得到了: - 更换self.calloutAnnotation.coordinate = coords; with self.calloutAnnotation.latitude = coords.latitude;self.calloutAnnotation.longitude = coords.longitude;- 更改后,如果我在更新图钉后稍微捏住地图来放大或缩小,标注注释会动画到图钉正上方的正确位置。

所以现在我需要弄清楚如何在用户不必实际捏合缩放的情况下实现这一点。


原帖

我和其他 SO 用户一起使用这个很棒的解决方案来创建自定义标注注释:http://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/

当您使用标准标注 (annotationview.canShowCallout = true) 并且图钉在位置更新时在屏幕上移动时,标准标注会与图钉一起跟踪,就好像它们锁定在一起一样。

使用上面的自定义标注解决方案时,当我的图钉在位置更新后四处移动时,标注注释将保留在其原始位置。当然,我想模仿 iOS 标准并拥有自定义标注注释轨道和引脚。

这是我到目前为止的代码,它成功移动了注释视图,但没有移动自定义标注注释视图:



/* core location broadcasts a notification, and my view controller listens to that notification and calls locationManagerDidFindLocation */
- (void)locationManagerDidFindLocation:(NSNotification *)notif {
    CLLocation *location = [notif.userInfo objectForKey:@"location"];
    CLLocationCoordinate2D coords = [location coordinate];
    MKCoordinateSpan span = MKCoordinateSpanMake((5/69), (5/69));
    MKCoordinateRegion region = {coords, span};

    // if we don't have a current location yet, create one, place it on the map, and adjust the map's region
    // otherwise, update the annotation placement and map position in a smooth animation
    if (self.currentLocationAnnotation == nil) {
        self.currentLocationAnnotation = [[CurrentLocationAnnotation alloc] initWithCoordinate:coords andTitle:@"My Title" andSubtitle:@"My subtitle"];

        [self.mapView addAnnotation:self.currentLocationAnnotation];
        [self.mapView setRegion:region animated:true];
        [self.mapView regionThatFits:region];
    } else {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.45];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

            // this moves my annotation view perfectly
            self.currentLocationAnnotation.coordinate = coords;

            // ******* this is where my problem is
            // ******* this custom callout annotation view stays
            // ******* in it's original place, even though it's
            // ******* parent annotation view is moving around the screen
            self.calloutAnnotation.coordinate = coords;

            [self.mapView setRegion:region animated:true];
            [self.mapView regionThatFits:region];
        [UIView commitAnimations];
    }
}
  

custom callout

我根据您的 CalloutMapAnnotationView 创建了一个项目,演示了基于 IB 的解决方案。箭头键可以为位置注释及其标注注释的运动设置动画。标注现在还会根据提供的 contentView 自动调整大小,并且视图是从单独的笔尖加载的。祝你好运!

https://github.com/jacoobjennings/JJMapCallout

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MKAnnotationView - 锁定自定义注释视图以固定位置更新 的相关文章

随机推荐