GMSGroundOverlay 动画-我应该使用 CATiledLayer 吗?

我正在试验用于 iOS SDK 的谷歌地图最新版本1.2.1.2944来动画一个 GMSGroundOverlay。用户可以控制图像序列,所以使用一个动画 UIImage是不可能的,可惜,所以我在加载的 UIImage在飞行。GMSGroundOverlay.icon被设置为正在更新的 UIImage

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

我突然想到,也许我应该利用 CATiledLayer来处理图像,只加载到内存中,然后进入 GMSGroundOverlay的图标属性,但是有人有任何经验使用 CATiledLayer与谷歌地图的 iOS SDK 和序列图像作为一个动画 GMSGroundOverlay

2121 次浏览

I got this answer from pressinganswer.com, i think it may helps you.

As currently I cannot use the "position" keypath for animating, I ended up animating it using the "latitude" and "longitude" keypaths separately.

First calculate the points and add them to 2 separate arrays, one for latitude value (y) and one for longitude (x) and then use the values property in CAKeyFrameAnimation to animate. Create 2 CAKeyFrameAnimation objects (1 for each axis) and group them together using CAAnimationGroup and animate them together to form a circle.

In my equation I vary the length of the radius on each axis so that I can also generate an oval path.

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]];