【问题标题】:GMSGroundOverlay animating - should I be using a CATiledLayer?GMSGroundOverlay 动画 - 我应该使用 CATiledLayer 吗?
【发布时间】:2013-04-19 03:33:00
【问题描述】:

我正在尝试使用 Google Maps for iOS SDK 最新版本 1.2.1.2944 为 GMSGroundOverlay 设置动画。用户可以控制图像序列,因此遗憾的是不可能使用动画UIImage,所以我正在即时加载UIImageGMSGroundOverlay.icon 设置为正在更新的UIImage

除了高内存使用之外,我似乎遇到了一个限制,即每当我尝试使用大于 1000 像素 x 1000 像素的 GMSGroundOverlay.icon 覆盖 UIImage 时,它就会崩溃。引用 1000px x 1000px 的 UIImage 可以避免崩溃。

虽然我觉得也许我应该使用CATiledLayer 来处理图像以仅加载到内存中,然后加载到GMSGroundOverlay 的图标属性中,但是有没有人有任何使用CATiledLayer 和谷歌地图的经验iOS SDK 和序列图像作为动画GMSGroundOverlay?

【问题讨论】:

  • 我遇到了同样的问题,尽管我看到的崩溃阈值甚至更低。我很想看到这个问题的解决方案。
  • 我想要各种 GMSOverlays 的解决方案
  • 我不明白你想如何使用 TiledLayer..覆盖使用 UIImage ...

标签: ios crash overlay google-maps-sdk-ios catiledlayer


【解决方案1】:

我从 pressanswer.com 得到这个答案,我想它可能对你有帮助。

由于目前我无法使用“位置”键路径进行动画制作,因此我最终分别使用“纬度”和“经度”键路径对其进行动画处理。

首先计算点并将它们添加到 2 个单独的数组中,一个用于纬度值 (y),一个用于经度 (x),然后使用 CAKeyFrameAnimation 中的 values 属性进行动画处理。创建 2 个 CAKeyFrameAnimation 对象(每个轴 1 个)并使用 CAAnimationGroup 将它们组合在一起,并将它们动画在一起形成一个圆圈。

在我的方程式中,我改变了每个轴上的半径长度,这样我也可以生成椭圆路径。

NSMutableArray *latitudes = [NSMutableArray arrayWithCapacity:21];
    NSMutableArray *longitudes = [NSMutableArray arrayWithCapacity:21];
    for (int i = 0; i <= 20; i++) {
        CGFloat radians = (float)i * ((2.0f * M_PI) / 20.0f);

        // Calculate the x,y coordinate using the angle
        CGFloat x = hDist * cosf(radians);
        CGFloat y = vDist * sinf(radians);

        // Calculate the real lat and lon using the
        // current lat and lon as center points.
        y = marker.position.latitude + y;
        x = marker.position.longitude + x;


        [longitudes addObject:[NSNumber numberWithFloat:x]];
        [latitudes addObject:[NSNumber numberWithFloat:y]];
    }

    CAKeyframeAnimation *horizontalAnimation = [CAKeyframeAnimation animationWithKeyPath:@"longitude"];
    horizontalAnimation.values = longitudes;
    horizontalAnimation.duration = duration;

    CAKeyframeAnimation *verticleAnimation = [CAKeyframeAnimation animationWithKeyPath:@"latitude"];
    verticleAnimation.values = latitudes;
    verticleAnimation.duration = duration;

    CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
    group.animations = @[horizontalAnimation, verticleAnimation];
    group.duration = duration;
    group.repeatCount = HUGE_VALF;
    [marker.layer addAnimation:group forKey:[NSString stringWithFormat:@"circular-%@",marker.description]];

【讨论】:

  • 这不是 GMSGroundOverlay。您正在显示 GMSMarker。叠加层不提供对“层”的相同访问权限
猜你喜欢
  • 2016-09-23
  • 2017-10-24
  • 2022-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-26
相关资源
最近更新 更多